<?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: Getting the oldest entry side by side with the new ones in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Getting-the-oldest-entry-side-by-side-with-the-new-ones/m-p/566474#M17389</link>
    <description>&lt;P&gt;Would this work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Make sure it is sorted correctly. Might have to fix this according to your needs.;
proc sort data=enter out=have; 
	by id new;
run;

data want;
	set have;
	by id;
	length _old_original $4;
	retain _old_original; *Keep this variable over iterations of the indata.;
	if first.id then do;
		_old_original = new; *Save the original value in a temporary variable;
	end;
	else do;
		old = _old_original;
	end;
	drop _:; *Drop the temporary variable;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 17 Jun 2019 01:23:18 GMT</pubDate>
    <dc:creator>heffo</dc:creator>
    <dc:date>2019-06-17T01:23:18Z</dc:date>
    <item>
      <title>Getting the oldest entry side by side with the new ones</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Getting-the-oldest-entry-side-by-side-with-the-new-ones/m-p/566473#M17388</link>
      <description>&lt;P&gt;I have a dataset (enter) with id variable, and new and old entries for a product. I am trying to have the 'old' variable represent the oldest entry to the product. Currently, the 'old' variable represent an immediate old entry. Also, the variables may not be ordered as shown in the 'enter' dataset (3rd entry may be the fifth, for instance). The final dataset should look like the 'want' dataset as shown below. I tried creating a new variable to work around, but I am stuck at this. Thank you in advance!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data enter;
input id $ new $ old $;
datalines;
A 123P .
A 45X5 123P
A 678B 45X5
A 87E2 678B
A 95Y0 87E2
;
run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input id $ new $ old $;
datalines;
A 123P .
A 45X5 123P
A 678B 123P
A 87E2 123P
A 95Y0 123P
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table try as 
select *, case when old eq '' then new else old end as old_1
from enter
order by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2019 01:09:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Getting-the-oldest-entry-side-by-side-with-the-new-ones/m-p/566473#M17388</guid>
      <dc:creator>Mahip</dc:creator>
      <dc:date>2019-06-17T01:09:04Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the oldest entry side by side with the new ones</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Getting-the-oldest-entry-side-by-side-with-the-new-ones/m-p/566474#M17389</link>
      <description>&lt;P&gt;Would this work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Make sure it is sorted correctly. Might have to fix this according to your needs.;
proc sort data=enter out=have; 
	by id new;
run;

data want;
	set have;
	by id;
	length _old_original $4;
	retain _old_original; *Keep this variable over iterations of the indata.;
	if first.id then do;
		_old_original = new; *Save the original value in a temporary variable;
	end;
	else do;
		old = _old_original;
	end;
	drop _:; *Drop the temporary variable;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Jun 2019 01:23:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Getting-the-oldest-entry-side-by-side-with-the-new-ones/m-p/566474#M17389</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-06-17T01:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the oldest entry side by side with the new ones</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Getting-the-oldest-entry-side-by-side-with-the-new-ones/m-p/566475#M17390</link>
      <description>&lt;P&gt;Probably the same, but I had already written it!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data enter;
	input id $ new $ old $;
	datalines;
A 123P .
A 45X5 123P
A 678B 45X5
A 87E2 678B
A 95Y0 87E2
;
run;

data Want(drop=_:);
	length _Holdold $8;
	retain _Holdold;
	set enter;
	by id;

	if first.id then
		_Holdold = new;
	else old = _Holdold;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Jun 2019 01:28:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Getting-the-oldest-entry-side-by-side-with-the-new-ones/m-p/566475#M17390</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2019-06-17T01:28:54Z</dc:date>
    </item>
  </channel>
</rss>

