Anda di halaman 1dari 9

SAS Functions

SAS functions
When planning modifications to SAS datasets,
examine the many SAS functions that are
available
SAS has many built in functions that greatly
reduce the need to enter commands
SAS functions are pre-written expressions that
provide shortcuts for many calculations and
manipulations of data

Some Arithmetic Functions


1.

SQRT(value) returns the square root of value

2.

LOG/LOG2/LOG10 - calculates the logarithm to the base


e/2/10

3.

newx = ABS (x);

MOD(value,divisor) returns the integer remainder when


value is divided by divisor

5.

newx = LOG (x);

ABS(value) returns the absolute value of the numeric


argument

4.

newx = SQRT(x);

newx = MOD (x,3);

EXP(value) returns the constant e raised to the power


given by value.
3

Some Sample Statistic


Functions
MEAN (v1,v2,...,vn) - computes the arithmetic mean
(average)
2. CV (v1,v2,...,vn) - calculates the coefficient of variation
3. MAX (v1,v2,...,vn) - returns the largest value
4. MIN (v1,v2,...,vn) - returns the smallest value
5. N (v1,v2,...,vn) - returns the number of nonmissing
arguments
6. NMISS (v1,v2,...,vn) - returns the number of missing
arguments
7. RANGE (v1,v2,...,vn) - calculates the range
8. STD (v1,v2,...,vn) - calculates the standard deviation
9. STDERR (v1,v2,...,vn) - calculates the standard error of
the mean
10. SUM(v1,v2,...,vn) - calculates the sum of the arguments
1.

Some Truncation Functions


1.
2.
3.
4.

CEIL (value): returns the smallest integer greater


than or equal to the argument
FLOOR (value): returns the largest integer less
than or equal to the argument
INT (value): returns the integer value
ROUND(value,decimals) returns value rounded o
to the nearest value based upon the decimals
value.

newx1 = ROUND (x, 0.01);


newx2 = ROUND (x, 0.1);

Some Character Functions


1.

2.

3.

SCAN(string,n,delimiters): returns the nth word from


the character string string, where words are delimited
by the characters in delimiters. If delimiters is omitted
from the function, then blanks and most punctuation
and special characters are used as the delimiters.
SUBSTR(string,start,n): returns a substring or part of
string beginning with the character at the position start
in the string and continuing for n characters. If n is
omitted, then the remainder of the string is extracted.
SUBSTR(string1,start)=string2: replaces the characters
in string1 beginning at position start in string1 with
string2.

Some Character Functions


4.
5.
6.
7.

LOWCASE(string) - converts all to lowercase


UPCASE (string) - converts to uppercase
COMPRESS(string): returns a new string that has
blanks removed and then padded at the end of the
string
INDEX(string,value):returns the position in the
string where the rst character of value begins within
the string. If value is not contained within the string,
then the function returns zero

Some Date and Time


Functions
1.

MDY - returns a SAS date value from month, day,


and year

2.

DAY - returns the day of the month from a SAS date


value

3.

DAY ('17OCT91'D) give a number 17

MONTH - returns the month from a SAS date value


or literal

4.

For example, MDY(10,17,91) returns the SAS date value


'17OCT91'D

MONTH ('17OCT91'D) give a number 10

YEAR - returns the year from a SAS date value

YEAR ('17OCT91'D) give a 4-digit number 1991


8

Some Date and Time


Functions
5.
6.

DATE() & TODAY(): with no argument returns the


current system date
WEEKDAY(date): returns an integer from 1 to 7,
1=Sunday, 7=Saturday, corresponding to the day of
the week for the SAS date date

Anda mungkin juga menyukai