/********************************************* Information on SAS Operators and Functions Command file: functions.sas **********************************************/ /*SPECIFY GENERIC OUTPUT USING OPTIONS FORMCHAR= */ options formchar="|----|+|---+=|-/\<>*"; /*Math Operators*/ data math; input x y; /*mathematical functions*/ absx = abs(x); sqrtx = sqrt(x); log10y = log10(y); lny = log(y); int_y = int(y); roundy = round(y,.1); /*arithmetic operators*/ mult = x*y; divide = x/y; expon = x**y; tot = x + y; diff = x - y; cards; 4 5.23 -15 22.0 . 18.51 -1 3 6 0 5 5.035 ; proc print data=math; run; /*Statistical Functions*/ data salary; input SAL01 SAL02 SAL03; AvgSalary = mean(SAL01,SAL02,SAL03); StdSalary = std(SAL01,SAL02,SAL03); MaxSalary = max(SAL01,SAL02,SAL03); YrsSalary = n(SAL01,SAL02,SAL03); TotSalary = sum(SAL01,SAL02,SAL03); format SAL01 SAL02 SAL03 AvgSalary MaxSalary TotSalary dollar9.; cards; 50000 55000 60000 . 65000 70000 . . 52000 50000 . . ; title "Salary Example"; proc print data=salary; run; /*Different ways to calculate the mean*/ data salary2; input SAL01 SAL02 SAL03; AvgSalary = mean(SAL01,SAL02,SAL03); StdSalary = std(SAL01,SAL02,SAL03); MaxSalary = max(SAL01,SAL02,SAL03); YrsSalary = n(SAL01,SAL02,SAL03); TotSalary = sum(SAL01,SAL02,SAL03); if n(SAL01,SAL02,SAL03)>=2 then AvgSalary2 = mean(SAL01,SAL02,SAL03); format SAL01 SAL02 SAL03 AvgSalary AvgSalary2 MaxSalary TotSalary dollar9.; cards; 50000 55000 60000 . 65000 70000 . . 52000 50000 . . ; title "Salary Example, with Two Ways of Calculating Mean"; proc print data=salary2; var SAL01 SAL02 SAL03 AvgSalary AvgSalary2; run;