Hi all.
I'm trying to build new functions with the FCMP procedure (on SAS 9.2), and I'm having strange results with that one : I want to divide the current value by the one that was read on the previous observation.
As in a Data step, I tried the LAG function : no error there, and reading the online doc for FCMP, I did not read that LAG was a forbidden function.
[pre]
PROC FCMP OUTLIB=work.funcTest.test ;
FUNCTION ratio (variable) ;
prev = LAG(variable) ;
IF prev NE . THEN r = variable / prev ;
ELSE r = . ;
RETURN(r) ;
ENDSUB ;
RUN ; QUIT ;
[/pre]
The strange thing is, during execution, the LAG function does not seem to return the previous value, but the current one ! So I always end up with a result of 1 for my function.
[pre]
OPTION CMPLIB=(work.funcTest) ;
DATA work.test ;
SET sashelp.class ;
r = ratio(weight) ;
vPrec = LAG(weight) ;
IF vPrec NE . THEN r2 = weight / vPrec ;
ELSE r2 = . ;
RUN ;
PROC PRINT ;
RUN ;
[/pre]
Comparing with the hard-coded version, it seems that the formula is correct... but that LAG is not supported properly by FCMP.
Any help from some experienced FCMP user ? Thanks in advance.
Olivier