<?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: How to let the id of last row to be the new variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-let-the-id-of-last-row-to-be-the-new-variable/m-p/775123#M246401</link>
    <description>&lt;P&gt;Thank you so much!&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if now I want the new_id in the first row is equal to first id value (aa), what should I do?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;id&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;var1&lt;/TD&gt;&lt;TD&gt;var2&lt;/TD&gt;&lt;TD&gt;new id&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;aa&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;aa&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Bb&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;aa&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Cc&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;16&lt;/TD&gt;&lt;TD&gt;Bb&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Tue, 19 Oct 2021 13:37:25 GMT</pubDate>
    <dc:creator>HAHA888</dc:creator>
    <dc:date>2021-10-19T13:37:25Z</dc:date>
    <item>
      <title>How to let the id of last row to be the new variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-let-the-id-of-last-row-to-be-the-new-variable/m-p/775109#M246396</link>
      <description>&lt;P&gt;I want to compare the id is it same or not by comparing them in a same row.&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I tried this data step, Can someone help me :&lt;/P&gt;&lt;P&gt;data temp;&lt;BR /&gt;input id $ var1 var2;&lt;BR /&gt;New_id= id;&lt;BR /&gt;datalines;&lt;BR /&gt;aa 12 13&lt;BR /&gt;Bb 13 14&lt;BR /&gt;Cc 15 16&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;var1&lt;/TD&gt;&lt;TD&gt;var2&lt;/TD&gt;&lt;TD&gt;new id&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;aa&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Bb&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;aa&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Cc&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;16&lt;/TD&gt;&lt;TD&gt;Bb&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 19 Oct 2021 13:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-let-the-id-of-last-row-to-be-the-new-variable/m-p/775109#M246396</guid>
      <dc:creator>HAHA888</dc:creator>
      <dc:date>2021-10-19T13:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to let the id of last row to be the new variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-let-the-id-of-last-row-to-be-the-new-variable/m-p/775113#M246398</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set temp;
   newid = lag(id);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Oct 2021 13:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-let-the-id-of-last-row-to-be-the-new-variable/m-p/775113#M246398</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-10-19T13:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to let the id of last row to be the new variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-let-the-id-of-last-row-to-be-the-new-variable/m-p/775118#M246400</link>
      <description>&lt;P&gt;For values of a previous observation, you use the LAG function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_id = lag(id);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Oct 2021 13:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-let-the-id-of-last-row-to-be-the-new-variable/m-p/775118#M246400</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-19T13:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to let the id of last row to be the new variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-let-the-id-of-last-row-to-be-the-new-variable/m-p/775123#M246401</link>
      <description>&lt;P&gt;Thank you so much!&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if now I want the new_id in the first row is equal to first id value (aa), what should I do?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;id&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;var1&lt;/TD&gt;&lt;TD&gt;var2&lt;/TD&gt;&lt;TD&gt;new id&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;aa&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;aa&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Bb&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;aa&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Cc&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;16&lt;/TD&gt;&lt;TD&gt;Bb&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 19 Oct 2021 13:37:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-let-the-id-of-last-row-to-be-the-new-variable/m-p/775123#M246401</guid>
      <dc:creator>HAHA888</dc:creator>
      <dc:date>2021-10-19T13:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to let the id of last row to be the new variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-let-the-id-of-last-row-to-be-the-new-variable/m-p/775125#M246402</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;But if now I want the new_id in the first row is equal to first id value (aa), what should I do?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;id&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;var1&lt;/TD&gt;&lt;TD&gt;var2&lt;/TD&gt;&lt;TD&gt;new id&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;aa&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;aa&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Bb&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;aa&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Cc&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;16&lt;/TD&gt;&lt;TD&gt;Bb&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 19 Oct 2021 13:38:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-let-the-id-of-last-row-to-be-the-new-variable/m-p/775125#M246402</guid>
      <dc:creator>HAHA888</dc:creator>
      <dc:date>2021-10-19T13:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to let the id of last row to be the new variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-let-the-id-of-last-row-to-be-the-new-variable/m-p/775142#M246407</link>
      <description>&lt;P&gt;I think everyone's getting a little confused because your want data set keeps getting changed. Below is a cheap way to get what you want since the first record doesn't have a lag value to look for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set temp;
	new_id = lag(id);
	if missing(new_id) then new_id = id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;id var1 var2 New_id 
aa 12 13 aa 
Bb 13 14 aa 
Cc 15 16 Bb 
&lt;/PRE&gt;
&lt;P&gt;Can't guarantee this will hold up depending on the complexity of your actual data set.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 14:34:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-let-the-id-of-last-row-to-be-the-new-variable/m-p/775142#M246407</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-10-19T14:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to let the id of last row to be the new variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-let-the-id-of-last-row-to-be-the-new-variable/m-p/775152#M246410</link>
      <description>&lt;P&gt;Just add an additional override:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
new_id = lag(id);
if _n_ = 1 then new_id = id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Oct 2021 15:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-let-the-id-of-last-row-to-be-the-new-variable/m-p/775152#M246410</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-19T15:18:57Z</dc:date>
    </item>
  </channel>
</rss>

