SAS PROGRAMMING HANDOUT #6 SAS FUNCTIONS SAS allows many functions to be used in the data step, for example: +,-,/,* plus, minus, divide, multiply ABS(X) absolute value of x LOG(X) natural logarithm of x (base e) LOG10(X) logarith base 10 of x EXP(X) exponential of x SQRT(X) computes square root of x MEAN(X1,X2,...) generates the mean of X1,X2... (non-missing values) STD(X1,X2....) generates the standard deviation of X1,X2... STDERR(X1,X2...) generates the standard error of X1,X2... MIN(X1,X2....) generates the minimium of X1,X2... MAX(X1,X2....) generates the maximium value of X1,X2.... SUM(X1,X2...) generates the sum of X1,X2,... INT(X) computes the integer part ROUND(X) round off x FLOOR(X) computes largest integer less than x LAG(X) computes the previous x-value COS(X), TAN(X), SIN(X) cosine, sine, tangent of x (angle in radians) ARCOS(X), ARSIN(X), ATAN(X) arc-cosine, sine, tangent of x COSH(X), SINH(X), TANH(X) hyperbolic cosine sine, tangent of x GAMMA(X) computes gamma function of x PROBNORM(X) computes probs for normal, PROBNORM(1.96)=.975 PROBCHI(X,df) computes probs for chisq, PROBCHI(3.247,10)=.025 PROBT(X,df) computes probs for t-dist, PROBT(2.228,10)=.975 PROBF(x,ndf,ddf) computes probs for F-dist, PROBF(3.33,5,10)=.95 PROBBNML(p,n,m) computes probs for binom, PROBBNML(.5,10,4)=.377 PROBIT(P) computes inverse normal values, PROBIT(.975)=1.96 TINV(P) computes inverse t-values, TINV(.975,10)=2.228 GAMINV(P,eta) computes inverse gammas parameter eta RANNOR(0),NORMAL(0) generates a random normal value mean 0, sd 1 RANBIN(0,n,p) generates a random binomial (n,p) RANGAM(,0,alpha) generates a random gamma value with parameter alpha 2*RANGAM(0,alpha) generates a random chisquare with df=2*alpha RANPOI(0,lamb) generates a random Poisson with mean lamb MDY(month,day,year) generates a SAS date value TODAY() generates todays date DAY(date) generates day of month of date (also MONTH,YEAR functions) WEEKDAY(date) generates the day of week (1=Sunday, etc) ZIPNAME(zipcode) generates the state name of the zipcode SUBSTR used to truncate character variables, for example, if X equals ABCDEFG then Y=SUBSTR(X,2,3) equals BCD. SUBSTR(X,1,3)='AAA'; changes X to equal AAADEFG SCAN SCAN returns the nth word separted by the delimiter For example if A is AB?CDE?GHIJ then B=SCAN(A,2,'?') is CDE If the delimiter is not specified then it is assumed to be: blank,.,;,<,(,+,etc Thus is A is A.BC1);