<?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: Lagged variables problems in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Lagged-variables-problems/m-p/73816#M21412</link>
    <description>Hi:&lt;BR /&gt;
  These Tech Support notes and the documentation link illustrate the wrong and right ways to use the LAG function. LAG only puts a value in the queue when it is called. Therefore, it is better to do your lag OUTSIDE of any condition, get a value in the queue and then deal with the manipulations using the lagged value inside your conditional logic -- but don't use the LAG function itself inside the conditional logic. For more information, refer to the documentation....or if you get stuck, you might consider working with Tech Support on this issue.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/etsug_tsdata_sect048.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/etsug_tsdata_sect048.htm&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/24/665.html" target="_blank"&gt;http://support.sas.com/kb/24/665.html&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/25/938.html" target="_blank"&gt;http://support.sas.com/kb/25/938.html&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/24/694.html" target="_blank"&gt;http://support.sas.com/kb/24/694.html&lt;/A&gt;</description>
    <pubDate>Thu, 12 Feb 2009 15:33:16 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2009-02-12T15:33:16Z</dc:date>
    <item>
      <title>Lagged variables problems</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lagged-variables-problems/m-p/73814#M21410</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I'm a beginner sas user and having trouble using lagged variables. I'm trying to create a decay curve that switches to a linear function at some point.&lt;BR /&gt;
&lt;BR /&gt;
Code:&lt;BR /&gt;
&lt;BR /&gt;
DATA GEVS.EPS_Decay_Curve;&lt;BR /&gt;
	power = 0.7;&lt;BR /&gt;
	tgr = 4.5;&lt;BR /&gt;
	max_growth = 12;&lt;BR /&gt;
	max_years = 50;&lt;BR /&gt;
&lt;BR /&gt;
	do X = 1 to max_years;&lt;BR /&gt;
		Y = 1/((X+1)**power);&lt;BR /&gt;
		A = (max_growth - tgr)*Y;&lt;BR /&gt;
		Increment =  lag(A) - A;&lt;BR /&gt;
		SLAmt = A/(max_years-X);&lt;BR /&gt;
&lt;BR /&gt;
		/* Define when to jump to linear decay */&lt;BR /&gt;
		if Increment&lt;SLAMT then=""&gt;&lt;BR /&gt;
			do;&lt;BR /&gt;
				if X=1 then&lt;BR /&gt;
					Switch =0;&lt;BR /&gt;
				else do;&lt;BR /&gt;
					Switch = 1;&lt;BR /&gt;
				end;&lt;BR /&gt;
			end;&lt;BR /&gt;
		else &lt;BR /&gt;
			Switch =0;&lt;BR /&gt;
		&lt;BR /&gt;
		/* Calculate inc_f */&lt;BR /&gt;
		/* Store lags  */&lt;BR /&gt;
		lagswitch = lag(switch);&lt;BR /&gt;
		laginc_f = lag(inc_f);&lt;BR /&gt;
		lagSLAmt = lag(SLAmt);&lt;BR /&gt;
&lt;BR /&gt;
		if switch = 0 then&lt;BR /&gt;
			inc_f = Increment;&lt;BR /&gt;
		else if switch = 1 &amp;amp;&amp;amp; lagswitch = 0 then &lt;BR /&gt;
			inc_f = lagSLAmt;&lt;BR /&gt;
		else &lt;BR /&gt;
			inc_f = laginc_f;&lt;BR /&gt;
		output;&lt;BR /&gt;
	end;&lt;BR /&gt;
&lt;BR /&gt;
	drop power tgr max_growth max_years lagswitch laginc_f lagSLAmt;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
For some reason the inc_f is not calculating correctly. It should display 0.02967 for all values where switch=1.&lt;BR /&gt;
&lt;BR /&gt;
Can someone help?&lt;BR /&gt;
&lt;BR /&gt;
Jer&lt;/SLAMT&gt;</description>
      <pubDate>Thu, 12 Feb 2009 14:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lagged-variables-problems/m-p/73814#M21410</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-02-12T14:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Lagged variables problems</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lagged-variables-problems/m-p/73815#M21411</link>
      <description>Calculate inc_f */&lt;BR /&gt;
		/* Store lags  */&lt;BR /&gt;
		lagswitch = lag(switch);&lt;BR /&gt;
		laginc_f = lag(inc_f);&lt;BR /&gt;
		lagSLAmt = lag(SLAmt);&lt;BR /&gt;
&lt;BR /&gt;
		if switch = 0 then&lt;BR /&gt;
			inc_f = Increment;&lt;BR /&gt;
		else if switch = 1 &amp;amp;&amp;amp; lagswitch = 0 then &lt;BR /&gt;
			inc_f = lagSLAmt;&lt;BR /&gt;
		else &lt;BR /&gt;
			inc_f = laginc_f;&lt;BR /&gt;
		output;&lt;BR /&gt;
	end;&lt;BR /&gt;
&lt;BR /&gt;
	drop power tgr max_growth max_years lagswitch laginc_f lagSLAmt;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
For some reason the inc_f is not calculating correctly. It should display 0.02967 for all values where switch=1.&lt;BR /&gt;
&lt;BR /&gt;
Can someone help?&lt;BR /&gt;
&lt;BR /&gt;
Jer</description>
      <pubDate>Thu, 12 Feb 2009 14:30:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lagged-variables-problems/m-p/73815#M21411</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-02-12T14:30:03Z</dc:date>
    </item>
    <item>
      <title>Re: Lagged variables problems</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lagged-variables-problems/m-p/73816#M21412</link>
      <description>Hi:&lt;BR /&gt;
  These Tech Support notes and the documentation link illustrate the wrong and right ways to use the LAG function. LAG only puts a value in the queue when it is called. Therefore, it is better to do your lag OUTSIDE of any condition, get a value in the queue and then deal with the manipulations using the lagged value inside your conditional logic -- but don't use the LAG function itself inside the conditional logic. For more information, refer to the documentation....or if you get stuck, you might consider working with Tech Support on this issue.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/etsug_tsdata_sect048.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/etsug_tsdata_sect048.htm&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/24/665.html" target="_blank"&gt;http://support.sas.com/kb/24/665.html&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/25/938.html" target="_blank"&gt;http://support.sas.com/kb/25/938.html&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/24/694.html" target="_blank"&gt;http://support.sas.com/kb/24/694.html&lt;/A&gt;</description>
      <pubDate>Thu, 12 Feb 2009 15:33:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lagged-variables-problems/m-p/73816#M21412</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-02-12T15:33:16Z</dc:date>
    </item>
  </channel>
</rss>

