SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Search||next

Transforming Data with SAS Functions
Understanding SAS Functions


SAS functions are built-in expressions that enable you to complete many types of data manipulations quickly and easily. Generally speaking, functions provide programming shortcuts. There are a wide variety of SAS functions: mathematical functions, financial functions, character functions, probability functions, and many more.


Categories of SAS Functions
Array Probability
Bitwise Logical Operations Quantile
Character Random Number
Character String Matching Sample Statistics
Date and Time SAS File I/O
Dynamic Link Library Special
External Files State and ZIP Code
Financial Trigonometric
Hyperbolic Truncation
Macro Variable Control
Mathematical Variable Information
MultiByte Character Set  


Uses of SAS Functions

Using SAS functions, you can

  • calculate sample statistics
  • create SAS date values
  • convert ZIP codes to state postal codes
  • round values
  • generate random numbers
  • extract a portion of a character value
  • convert data from one data type to another.

This lesson concentrates on functions that

  • convert data
  • manipulate SAS date values
  • modify character variable values.

However, be sure to explore the many other SAS functions. Refer to SAS Language Reference: Dictionary for more information.


Example of a SAS Function

SAS functions can be used in DATA step programming statements and in some statistical procedures. A SAS function can be specified anywhere that you would use a SAS expression, as long as the function is part of a SAS statement.

Let's look at a simple example of a SAS function. The assignment statement below uses the MEAN function to calculate the average of three exam scores, stored in the variables Exam1, Exam2, and Exam3.

     AvgScore=mean(exam1,exam2,exam3);

When you reference a SAS function, the function returns a value based on the function arguments. The MEAN function above contains three arguments, the variables Exam1, Exam2, and Exam3. The function calculates the mean of the three variables listed as arguments.

Some functions require a specific number of arguments, while other functions may contain any number of arguments. Some functions require no arguments.


|next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement