<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Proc FCMP and LAG function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-FCMP-and-LAG-function/m-p/16631#M2330</link>
    <description>Perhaps the function will need two arguments and the second is lag.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
   ratio = ratio(variable,lag(variable));&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
How about divide;&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
   r3 = divide(weight,lag(weight));&lt;BR /&gt;
[/pre]

Message was edited by: data _null_;</description>
    <pubDate>Wed, 08 Apr 2009 21:56:06 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2009-04-08T21:56:06Z</dc:date>
    <item>
      <title>Proc FCMP and LAG function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-FCMP-and-LAG-function/m-p/16629#M2328</link>
      <description>Hi all.&lt;BR /&gt;
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.&lt;BR /&gt;
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.&lt;BR /&gt;
[pre]&lt;BR /&gt;
PROC FCMP OUTLIB=work.funcTest.test ;&lt;BR /&gt;
	FUNCTION ratio (variable) ;&lt;BR /&gt;
		prev = LAG(variable) ;&lt;BR /&gt;
		IF prev NE . THEN r = variable / prev ;&lt;BR /&gt;
		ELSE r = . ;&lt;BR /&gt;
		RETURN(r) ;&lt;BR /&gt;
	ENDSUB ;&lt;BR /&gt;
RUN ; QUIT ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
The strange thing is, during execution, the LAG function does not seem to return the previous value, but the &lt;I&gt;current&lt;/I&gt; one ! So I always end up with a result of 1 for my function.&lt;BR /&gt;
[pre]&lt;BR /&gt;
OPTION CMPLIB=(work.funcTest) ;&lt;BR /&gt;
DATA work.test ;&lt;BR /&gt;
	SET sashelp.class ;&lt;BR /&gt;
	r = ratio(weight) ;&lt;BR /&gt;
	vPrec = LAG(weight) ;&lt;BR /&gt;
	IF vPrec NE . THEN r2 = weight / vPrec ;&lt;BR /&gt;
	ELSE r2 = . ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
PROC PRINT ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Comparing with the hard-coded version, it seems that the formula is correct... but that LAG is not supported properly by FCMP.&lt;BR /&gt;
&lt;BR /&gt;
Any help from some experienced FCMP user ? Thanks in advance.&lt;BR /&gt;
Olivier</description>
      <pubDate>Wed, 08 Apr 2009 16:47:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-FCMP-and-LAG-function/m-p/16629#M2328</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2009-04-08T16:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Proc FCMP and LAG function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-FCMP-and-LAG-function/m-p/16630#M2329</link>
      <description>Oliver&lt;BR /&gt;
 &lt;BR /&gt;
I think this has to do with the concepts.&lt;BR /&gt;
Within a subsoutine/function all are local, except perhaps parameters. So from where should lag() access its lag-stack history? I assume it should be local. Certainly it differs from a data step lag() if the first call returns the input; &lt;BR /&gt;
In another non-data step context lag() doesn't function ~ when invoked inside %sysfunc() it is rejected at syntax level. I think lag() has more relevance in a subroutine/function, but it cannot interact with the data step lag stacks.&lt;BR /&gt;
 &lt;BR /&gt;
that's just my inference=guess&lt;BR /&gt;
 &lt;BR /&gt;
PeterC</description>
      <pubDate>Wed, 08 Apr 2009 19:44:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-FCMP-and-LAG-function/m-p/16630#M2329</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-04-08T19:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Proc FCMP and LAG function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-FCMP-and-LAG-function/m-p/16631#M2330</link>
      <description>Perhaps the function will need two arguments and the second is lag.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
   ratio = ratio(variable,lag(variable));&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
How about divide;&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
   r3 = divide(weight,lag(weight));&lt;BR /&gt;
[/pre]

Message was edited by: data _null_;</description>
      <pubDate>Wed, 08 Apr 2009 21:56:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-FCMP-and-LAG-function/m-p/16631#M2330</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-04-08T21:56:06Z</dc:date>
    </item>
    <item>
      <title>Re: Proc FCMP and LAG function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-FCMP-and-LAG-function/m-p/16632#M2331</link>
      <description>Peter,&lt;BR /&gt;
I do agree with you : having LAG work in any context would be really strange. That's why I was trying to use it in FCMP, expecting an error or warning message. But nothing came, except strange results.&lt;BR /&gt;
Moreover, when I run&lt;BR /&gt;
[pre]&lt;BR /&gt;
PROC FCMP LIST ;&lt;BR /&gt;
RUN ; QUIT ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
the Output shows :&lt;BR /&gt;
[pre]&lt;BR /&gt;
Listing of Variables used in the Program&lt;BR /&gt;
&lt;BR /&gt;
_N_ _ERROR_ _LIST_ _DELTA_ _DER_ _I_&lt;BR /&gt;
The Program Lag Length is 0.&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Does that mean that the "Lag length" can be tuned ? I didn't see any option about that.&lt;BR /&gt;
Maybe some SAS folk would have an answer.&lt;BR /&gt;
Thanks for your answers.&lt;BR /&gt;
Olivier</description>
      <pubDate>Thu, 09 Apr 2009 06:36:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-FCMP-and-LAG-function/m-p/16632#M2331</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2009-04-09T06:36:38Z</dc:date>
    </item>
  </channel>
</rss>

