<?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: add previous Observation to variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/add-previous-Observation-to-variable/m-p/18251#M3563</link>
    <description>Thanks. This is what Im looking for.&lt;BR /&gt;
&lt;BR /&gt;
Greetings&lt;BR /&gt;
&lt;BR /&gt;
Lex</description>
    <pubDate>Tue, 14 Apr 2009 12:45:52 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-04-14T12:45:52Z</dc:date>
    <item>
      <title>add previous Observation to variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/add-previous-Observation-to-variable/m-p/18248#M3560</link>
      <description>Hi all,&lt;BR /&gt;
&lt;BR /&gt;
I want to make a training curve. Therefore I must add the previous Observation to my variable "X".  &lt;BR /&gt;
OBServation1: X= Condition from OBS1&lt;BR /&gt;
OBServation2: X= x from OBS1 plus Condition from OBS2&lt;BR /&gt;
OBServation3: X= x from OBS2 plus Condition from OBS3&lt;BR /&gt;
OBServation4: X= x from OBS3 plus Condition from OBS4&lt;BR /&gt;
OBServation5: X= x from OBS4 plus Condition from OBS5&lt;BR /&gt;
OBServation6: X= x from OBS5 plus Condition from OBS6&lt;BR /&gt;
&lt;BR /&gt;
But I dont know how I get the previous Observation. Maybe have anybody an idea?&lt;BR /&gt;
&lt;BR /&gt;
Obs Condition X&lt;BR /&gt;
1  0  0   &lt;BR /&gt;
2  1  1&lt;BR /&gt;
3  1  2&lt;BR /&gt;
4  0  2&lt;BR /&gt;
5  0  2&lt;BR /&gt;
6  1  3&lt;BR /&gt;
&lt;BR /&gt;
Thanks, Lex</description>
      <pubDate>Tue, 14 Apr 2009 08:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/add-previous-Observation-to-variable/m-p/18248#M3560</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-14T08:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: add previous Observation to variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/add-previous-Observation-to-variable/m-p/18249#M3561</link>
      <description>data input;&lt;BR /&gt;
  input obs value;&lt;BR /&gt;
  datalines;&lt;BR /&gt;
1 0&lt;BR /&gt;
2 1&lt;BR /&gt;
3 1&lt;BR /&gt;
4 0&lt;BR /&gt;
5 0&lt;BR /&gt;
6 1&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data x;&lt;BR /&gt;
  set input;&lt;BR /&gt;
  retain x1;&lt;BR /&gt;
  x1 + value;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Or you could experiment with the LAG function - &lt;A href="http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000212547.htm" target="_blank"&gt;http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000212547.htm&lt;/A&gt;</description>
      <pubDate>Tue, 14 Apr 2009 09:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/add-previous-Observation-to-variable/m-p/18249#M3561</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2009-04-14T09:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: add previous Observation to variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/add-previous-Observation-to-variable/m-p/18250#M3562</link>
      <description>If I got this right, you should RETAIN variable X.&lt;BR /&gt;
&lt;BR /&gt;
Retain, holds the value of the previous iteration.&lt;BR /&gt;
&lt;BR /&gt;
Assuming that table1 holds the input data.&lt;BR /&gt;
&lt;BR /&gt;
data table2; &lt;BR /&gt;
set table1;&lt;BR /&gt;
retain X 0;  /* explicit retain for the X variable */&lt;BR /&gt;
X=X+Condition;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
or simply:&lt;BR /&gt;
&lt;BR /&gt;
data table2; &lt;BR /&gt;
set table1;&lt;BR /&gt;
X+Condition; /* implicit retain for the X variable, when using RETAIN_VAR+&lt;SOMETHING&gt; */&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Both are the same.&lt;BR /&gt;
On the latest, there's no need to explicitly use the retain statement.&lt;BR /&gt;
&lt;BR /&gt;
Greetings from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos at &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/SOMETHING&gt;</description>
      <pubDate>Tue, 14 Apr 2009 09:57:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/add-previous-Observation-to-variable/m-p/18250#M3562</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-04-14T09:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: add previous Observation to variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/add-previous-Observation-to-variable/m-p/18251#M3563</link>
      <description>Thanks. This is what Im looking for.&lt;BR /&gt;
&lt;BR /&gt;
Greetings&lt;BR /&gt;
&lt;BR /&gt;
Lex</description>
      <pubDate>Tue, 14 Apr 2009 12:45:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/add-previous-Observation-to-variable/m-p/18251#M3563</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-14T12:45:52Z</dc:date>
    </item>
  </channel>
</rss>

