<?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: Lag function Error in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/lag-function-Error/m-p/240290#M55591</link>
    <description>Do you understand my comment? If not, please post your whole code and log.  The code posted above isn't valid SAS syntax. As mentioned variables rarely start with numbers (1_GoldS)</description>
    <pubDate>Mon, 21 Dec 2015 18:00:52 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2015-12-21T18:00:52Z</dc:date>
    <item>
      <title>lag function Error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/lag-function-Error/m-p/240287#M55588</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have attached SAS Data Set, New_Gold needs to calculate as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If _n_ then .&lt;/P&gt;
&lt;P&gt;if _n_=2 then (Obs2-Obs1)^2&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;if _n_=3 then (obs3-obs2)^2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;if _n_=4 then (Obs4-Obs3)^2 etc&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;As a first step I am using Lag function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;New_Gold=Lag(1_GoldS)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;I am getting the follwing error, Please advise.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, &lt;BR /&gt; GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.&lt;/P&gt;
&lt;P&gt;ERROR 72-185: The LAG function call has too many arguments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Dec 2015 17:35:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/lag-function-Error/m-p/240287#M55588</guid>
      <dc:creator>Coa_SAs</dc:creator>
      <dc:date>2015-12-21T17:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: lag function Error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/lag-function-Error/m-p/240288#M55589</link>
      <description>The function is called is LAG&amp;lt;n&amp;gt; where &amp;lt;n&amp;gt; represents the amount of lag.&lt;BR /&gt;&lt;BR /&gt;Your code should be:&lt;BR /&gt; lag1(variable_name). &lt;BR /&gt;&lt;BR /&gt;Variables don't typically start with numbers, so perhaps its just a typo?</description>
      <pubDate>Mon, 21 Dec 2015 17:39:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/lag-function-Error/m-p/240288#M55589</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-21T17:39:45Z</dc:date>
    </item>
    <item>
      <title>Lag function Error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/lag-function-Error/m-p/240289#M55590</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have data as attached.&amp;nbsp;New_Gold needs to calculate as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If _n_ then .&lt;/P&gt;
&lt;P&gt;if _n_=2 then (Obs2-Obs1)^2&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if _n_=3 then (obs3-obs2)^2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;SPAN&gt;if _n_=4 then (Obs4-Obs3)^2 etc&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As a first step I am using Lag function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;New_Gold=Lag(1_GoldS)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am getting the follwing error, Please advise.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, &lt;BR /&gt;GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.&lt;/P&gt;
&lt;P&gt;ERROR 72-185: The LAG function call has too many arguments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Dec 2015 17:41:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/lag-function-Error/m-p/240289#M55590</guid>
      <dc:creator>Coa_SAs</dc:creator>
      <dc:date>2015-12-21T17:41:08Z</dc:date>
    </item>
    <item>
      <title>Re: Lag function Error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/lag-function-Error/m-p/240290#M55591</link>
      <description>Do you understand my comment? If not, please post your whole code and log.  The code posted above isn't valid SAS syntax. As mentioned variables rarely start with numbers (1_GoldS)</description>
      <pubDate>Mon, 21 Dec 2015 18:00:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/lag-function-Error/m-p/240290#M55591</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-21T18:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: Lag function Error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/lag-function-Error/m-p/240291#M55592</link>
      <description>&lt;P&gt;Thanks Reeza for your quick reply, I got it.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Dec 2015 18:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/lag-function-Error/m-p/240291#M55592</guid>
      <dc:creator>Coa_SAs</dc:creator>
      <dc:date>2015-12-21T18:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: lag function Error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/lag-function-Error/m-p/240292#M55593</link>
      <description>&lt;P&gt;Seems like you could get what you want with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;new_gold = dif(GoldS)**2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It will generate a missing value on the first observation, but that is expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are stuck on using LAG instead of DIF:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;new_gold = lag(GoldS);&lt;/P&gt;
&lt;P&gt;if _n_=1 then new_gold=.;&lt;/P&gt;
&lt;P&gt;else new_gold = (GoldS - new_gold)**2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that SAS uses ** (not ^) to indicate raising to a power.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Dec 2015 18:12:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/lag-function-Error/m-p/240292#M55593</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-12-21T18:12:58Z</dc:date>
    </item>
    <item>
      <title>Re: Lag function Error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/lag-function-Error/m-p/240294#M55594</link>
      <description>Please mark the question as answered.</description>
      <pubDate>Mon, 21 Dec 2015 18:14:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/lag-function-Error/m-p/240294#M55594</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-21T18:14:07Z</dc:date>
    </item>
  </channel>
</rss>

