University of Rochester Medical Center
SearchDirectoryNewsEventsStrong HealthURMC Home

SAS Helpful Hints

Commonly Used Functions

This is by no means a complete list. Just a few of my favorites.

 
Basic Math

c=a+b Addition
c=a-b Subtraction
c=a*b Multiplication
c=a/b Division
c=a**b Exponential

 
Numeric Functions

b=ABS(a); Absolute Value (a=-4.593, b=4.593)
b=INT(a); Integer (a=4.593, b=4)
b=ROUND(a); Round (a=4.593, b=5)
b=MOD(a,4); Remainder (a=6, b=2)
b=SQRT(a); Square Root (a=9, b=3)
b=EXP(a); Exponential (a=1, b=2.71828)
b=LOG(a) Natural Log (a=10, b=2.302585093)
b=LOG10(a) Log base 10 (a=10, b=1.0)
b=COS(a) Cosine
b=SIN(a) Sine
b=TAN(a) Tangent
b=RANUNI(seed) b=(a random number between 0.0 and 1.0)
b=SUM(7, 2.4, 3.6, 1) Sum (b=14)
b=MIN(7, 2.4, 3.6, 1) Minimum (b=1)
b=MAX(7, 2.4, 3.6, 1) Maximum (b=7)
b=MEAN(7, 2.4, 3.6, 1) Mean/Average (b=3.5)
b=STD(7, 2.4, 3.6, 1) Standard Deviation (b=2.56385)
b=STDERR(7, 2.4, 3.6, 1) Standard Error (b=1.28193)
b=VAR(7, 2.4, 3.6, 1) Variance (b=6.57333)
b=N(7, 2.4, 3.6, 1) N(# not missing) (b=4)
b=NMISS(7, 2.4, 3.6, 1) Number missing (b=0)
b=DIM(anarray) Number of element in an array

 

Date Functions

d=TODAY() Returns todays date
t=TIME() Returns the current time
d=MDY(month,day,year) Creates a date
t=HMS(hour,minute,second) Creates a time
d=DHMS(date,hour,minute,second) Creates a datetime variable
m=MONTH(date) Returns the month from a date variable
d=DAY(date) Returns the day from a date variable
y=YEAR(date) Returns the year from a date variable
w=WEEKDAY(date) Returns the day of week from a date
variable 1-7 (Sunday-Saturday)
h=HOUR(time) Returns the hours from a time variable
m=MINUE(time) Returns the minutes from a time variable
s=SECOND(time) Returns the seconds from a time variable
d=DATEPART(datetime) Returns the date from a datetime variable
age=YRDIF(dob,today(),'ACT/ACT') Returns exact # years between dob and today

 

Character Functions

x=y||z Concatenation
x=COMPRESS(y,'+y') Remove characters from a string
(y='abc+xyz', x='abcxz')
x=SUBSTR(y,start,length)
x=SUBSTR(y,2,3)
Cut part of a string
(y='xabcyz', x='abc')
a=LENGTH(y) Length of a string (y='Mouse', a=5)
a=INDEX(string,excerpt)
a=INDEX(y,'u')
Find the first occurence of excerpt in string
(y='Mouse', a=3)
x=LEFT(y) (y='    Mouse', x='Mouse    ')
x=RIGHT(y) (y='Mouse    ', x='    Mouse')
x=TRIM(y) (y='Mouse    ', x='Mouse')
x=LOWCASE(y) Lowercase string (y='MOUSE', x='mouse')
x=UPCASE(y) Uppercase string (y='Mouse', x='MOUSE')
x=TRANSLATE(source,to,from)
x=TRANSLATE("axbxc","+","x")
Replaces selected characters in a string.
x="a+b+c"
x=VLABEL(y) x=Label of y.
x=VTYPE(y) x=Type of y. (N if Numeric or C if Character)
x=VFORMAT(y) x=Format of y.

 

Please send your comments and suggestions about this web page to A. Watts (watts@bst.rochester.edu)