<?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 Choosing a variable from the next row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Choosing-a-variable-from-the-next-row/m-p/91428#M289783</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Suppose you've got a dataset with variables var1 and var2. When var1 is equal to a certain value, you want to take the value of var2 in the next row down.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do you do that?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Marco&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 24 Sep 2013 11:32:07 GMT</pubDate>
    <dc:creator>Lupacante</dc:creator>
    <dc:date>2013-09-24T11:32:07Z</dc:date>
    <item>
      <title>Choosing a variable from the next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choosing-a-variable-from-the-next-row/m-p/91428#M289783</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Suppose you've got a dataset with variables var1 and var2. When var1 is equal to a certain value, you want to take the value of var2 in the next row down.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do you do that?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Marco&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Sep 2013 11:32:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choosing-a-variable-from-the-next-row/m-p/91428#M289783</guid>
      <dc:creator>Lupacante</dc:creator>
      <dc:date>2013-09-24T11:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing a variable from the next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choosing-a-variable-from-the-next-row/m-p/91429#M289784</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's an example way to do it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set sashelp.class(rename=(height=var1 weight=var2));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if get_var2 then&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symputx('var2_value',var2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; stop;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if var1=57.3 then&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; get_var2+1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%put var2_value=&amp;amp;var2_value;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Sep 2013 11:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choosing-a-variable-from-the-next-row/m-p/91429#M289784</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2013-09-24T11:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing a variable from the next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choosing-a-variable-from-the-next-row/m-p/91430#M289785</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV style="font-family: Courier New; font-size: 11pt;"&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;data&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; next;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; sashelp.class &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;=eof;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;if&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;not&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; eof &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; sashelp.class(firstobs=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;2&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; keep=weight rename=(weight=_weight));&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; sex eq &lt;/SPAN&gt;&lt;SPAN style="color: #800080; background-color: #ffffff;"&gt;'F'&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;and&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;not&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; eof then weight=_weight;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;run&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Sep 2013 11:51:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choosing-a-variable-from-the-next-row/m-p/91430#M289785</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-09-24T11:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing a variable from the next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choosing-a-variable-from-the-next-row/m-p/91431#M289786</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data ds_view / view=ds_view;&lt;/P&gt;&lt;P&gt;merge ds1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ds1 (firstobs=2 keep=var2 rename=(var2=nextvar2));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want (drop=nextvar2);&lt;/P&gt;&lt;P&gt;set ds_view;&lt;/P&gt;&lt;P&gt;if var1=1 then var1=nextvar2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Sep 2013 11:55:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choosing-a-variable-from-the-next-row/m-p/91431#M289786</guid>
      <dc:creator>Keith</dc:creator>
      <dc:date>2013-09-24T11:55:26Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing a variable from the next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choosing-a-variable-from-the-next-row/m-p/91432#M289787</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Amir:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it successfully creates a dataset, but how do I then get the value for var2 for a particular one of var1? The dataset just has an extra column 'var2' which is zero everywhere except for that particular value of var1.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Sep 2013 12:33:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choosing-a-variable-from-the-next-row/m-p/91432#M289787</guid>
      <dc:creator>Lupacante</dc:creator>
      <dc:date>2013-09-24T12:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing a variable from the next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choosing-a-variable-from-the-next-row/m-p/91433#M289788</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you want to create:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A) A data set with one row showing the var1 value and the next var2 value&lt;/P&gt;&lt;P&gt;B) A macro variable holding the value&lt;/P&gt;&lt;P&gt;C) Something else, please specify with an example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I saw a post from you that has since been deleted saying that SAS did not recognise the macro variable reference, in that case try replacing:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;call symputx('var2_value',var2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;call symputx('var2_value',var2,'G');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to make the scope of the variable global, if, for example, it is being created in a macro function, and is being referenced outside of that macro function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Sep 2013 12:43:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choosing-a-variable-from-the-next-row/m-p/91433#M289788</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2013-09-24T12:43:49Z</dc:date>
    </item>
  </channel>
</rss>

