Using User-Defined Functions and Subroutines
/*--------------------------------------------------------------
SAS Sample Library
Name: tdtex02.sas
Description: Example program from SAS/ETS User's Guide,
The TIMEDATA Procedure
Title: Using User-Defined Functions and Subroutines
Product: SAS/ETS Software
Keys: user-defined function
PROC: TIMEDATA
Notes:
--------------------------------------------------------------*/
proc fcmp outlib=work.timefnc.funcs;
subroutine mylog(actual[*], transform[*]);
outargs transform;
actlen = DIM(actual);
do t = 1 to actlen;
transform[t] = log(actual[t]);
end;
endsub;
function mymean(actual[*]);
actlen = DIM(actual);
sum = 0;
do t = 1 to actlen;
sum = sum + actual[t];
end;
return( sum / actlen );
endsub;
run;
quit;
options cmplib = work.timefnc;
proc timedata data=sashelp.air out=work.air
print=(scalars arrays);
id date interval=qtr acc=t format=yymmdd.;
vars air;
outarrays logair myair;
outscalars mystats;
call mylog(air,logair);
do t = 1 to dim(air);
myair[t] = air[t] - logair[t];
end;
mystats= mymean(air);
run;