
USING SAS FUNCTIONS TO MANIPULATE YOUR DATA
When planning modifications to SAS data sets, be sure to examine the many SAS functions that are
available. SAS functions are prewritten expressions that provide programming shortcuts for many
calculations and manipulations of data. SAS functions can be used in DATA step programming
statements, PROC SQL 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.
SAS functions also ignore missing values.
How can I use a SAS function to create the average of three variables?
The assignment statement below uses the MEAN function to calculate the average of three exam scores
that are stored in the variables Exam1, Exam2, and Exam3. The function calculates the mean of the
three variables that are listed as arguments.
AvgScore=mean(exam1,exam2,exam3); 
How can I convert my data from character to numeric and visa versa using SAS functions?
To convert CHARACTER values to NUMERIC values you use the INPUT function and to convert NUMERIC
values to CHARACTER values you use the PUT function. The form of the INPUT and PUT functions
is as follows:
INPUT(source,informat) PUT(source,format) 
However, note that the INPUT function requires an informat, whereas the PUT function requires a
format.
To remember which function requires a format versus an informat, note that the INPUT function
requires the informat.
The following SAS code converts a numeric date value to a SAS date value stored as the number of
days from 1st January 1960 using the INPUT and PUT functions.
Numdate=122599;
Chardate=put(numdate,z6.);
Sasdate=input(Chardate,mmddyy6.); 
Some other useful SAS functions:
 COMPRESS: Removes specific characters from character expressions
 LOWCASE: Converts all letters in the argument to lowercase
 PROPERCASE: Upper case the first letter of each word, lowercase the rest
 SCAN: Returns the nth word from a string
 SUBSTR: Extracts a substring from an argument or replaces a string within an argument
 TRANSLATE: Replaces specific characters in a character expression with other characters
 TRANWRD: Replaces or removes all occurrences of a word in a character string
 TRIM: Removes trailing blanks from character expressions
Did you find this page useful?
If you have any comments or questions, feel free to contact us.
 
0845 402 9907

