<?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 Returning Earliest date by multiple Keys in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Returning-Earliest-date-by-multiple-Keys/m-p/781392#M249030</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's been quite some time since I've meddled with SAS but am really struggling to understand the logic here. I feel like I'm overcomplicating it. Below is what I have, want and what I've attempted (excluding the multiple variations).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Simply put. I want it to know is an ID's earliest revoke (revoke = 1) then that should be the date that is shown. If at anytime revoke swaps to 0 and back to 1 then I want this new date to show.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data have;
input ID Revoke date :datetime.;
format date datetime20.;
datalines;
1 0 01JAN2020:16:49:00
1 1 05JAN2020:16:49:00
1 1 10JAN2020:16:49:00
1 1 20JAN2020:16:49:00
2 0 01JAN2020:16:49:00
2 1 02JAN2020:16:49:00
2 0 23JUL2020:16:49:00
2 1 25JUL2020:16:49:00
2 1 02AUG2020:16:49:00
3 0 01JAN2020:16:49:00
3 0 03JUL2020:16:49:00
3 1 13JUL2020:16:49:00
3 1 23JUL2020:16:49:00
3 0 24JUL2020:16:49:00
3 1 25JUL2020:16:49:00
;

data want;
input ID Revoke date :datetime. NewDate :datetime.;
format date NewDate datetime20.;
datalines;
1 0 01JAN2020:16:49:00 .
1 1 05JAN2020:16:49:00 05JAN2020:16:49:00
1 1 10JAN2020:16:49:00 05JAN2020:16:49:00
1 1 20JAN2020:16:49:00 05JAN2020:16:49:00
2 0 01JAN2020:16:49:00 .
2 1 02JAN2020:16:49:00 02JAN2020:16:49:00 
2 0 23JUL2020:16:49:00 .
2 1 25JUL2020:16:49:00 25JUL2020:16:49:00
2 1 02AUG2020:16:49:00 25JUL2020:16:49:00
3 0 01JAN2020:16:49:00 .
3 0 03JUL2020:16:49:00 .
3 1 13JUL2020:16:49:00 13JUL2020:16:49:00
3 1 23JUL2020:16:49:00 13JUL2020:16:49:00
3 0 24JUL2020:16:49:00 .
3 1 25JUL2020:16:49:00 25JUL2020:16:49:00 
;

data testwant;
	set have;
	format newdate datetime20.;
	by id date revoke;
	if first.revoke then newDate = date;
	if revoke = 0 then newdate = .;
	if revoke = lag(revoke) and id = lag(id) then newDate = lag(newdate);
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;</description>
    <pubDate>Fri, 19 Nov 2021 21:26:24 GMT</pubDate>
    <dc:creator>Krueger1</dc:creator>
    <dc:date>2021-11-19T21:26:24Z</dc:date>
    <item>
      <title>Returning Earliest date by multiple Keys</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-Earliest-date-by-multiple-Keys/m-p/781392#M249030</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's been quite some time since I've meddled with SAS but am really struggling to understand the logic here. I feel like I'm overcomplicating it. Below is what I have, want and what I've attempted (excluding the multiple variations).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Simply put. I want it to know is an ID's earliest revoke (revoke = 1) then that should be the date that is shown. If at anytime revoke swaps to 0 and back to 1 then I want this new date to show.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data have;
input ID Revoke date :datetime.;
format date datetime20.;
datalines;
1 0 01JAN2020:16:49:00
1 1 05JAN2020:16:49:00
1 1 10JAN2020:16:49:00
1 1 20JAN2020:16:49:00
2 0 01JAN2020:16:49:00
2 1 02JAN2020:16:49:00
2 0 23JUL2020:16:49:00
2 1 25JUL2020:16:49:00
2 1 02AUG2020:16:49:00
3 0 01JAN2020:16:49:00
3 0 03JUL2020:16:49:00
3 1 13JUL2020:16:49:00
3 1 23JUL2020:16:49:00
3 0 24JUL2020:16:49:00
3 1 25JUL2020:16:49:00
;

data want;
input ID Revoke date :datetime. NewDate :datetime.;
format date NewDate datetime20.;
datalines;
1 0 01JAN2020:16:49:00 .
1 1 05JAN2020:16:49:00 05JAN2020:16:49:00
1 1 10JAN2020:16:49:00 05JAN2020:16:49:00
1 1 20JAN2020:16:49:00 05JAN2020:16:49:00
2 0 01JAN2020:16:49:00 .
2 1 02JAN2020:16:49:00 02JAN2020:16:49:00 
2 0 23JUL2020:16:49:00 .
2 1 25JUL2020:16:49:00 25JUL2020:16:49:00
2 1 02AUG2020:16:49:00 25JUL2020:16:49:00
3 0 01JAN2020:16:49:00 .
3 0 03JUL2020:16:49:00 .
3 1 13JUL2020:16:49:00 13JUL2020:16:49:00
3 1 23JUL2020:16:49:00 13JUL2020:16:49:00
3 0 24JUL2020:16:49:00 .
3 1 25JUL2020:16:49:00 25JUL2020:16:49:00 
;

data testwant;
	set have;
	format newdate datetime20.;
	by id date revoke;
	if first.revoke then newDate = date;
	if revoke = 0 then newdate = .;
	if revoke = lag(revoke) and id = lag(id) then newDate = lag(newdate);
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Nov 2021 21:26:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-Earliest-date-by-multiple-Keys/m-p/781392#M249030</guid>
      <dc:creator>Krueger1</dc:creator>
      <dc:date>2021-11-19T21:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: Returning Earliest date by multiple Keys</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-Earliest-date-by-multiple-Keys/m-p/781396#M249032</link>
      <description>&lt;P&gt;How about&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Revoke date :datetime.;
format date datetime20.;
datalines;
1 0 01JAN2020:16:49:00
1 1 05JAN2020:16:49:00
1 1 10JAN2020:16:49:00
1 1 20JAN2020:16:49:00
2 0 01JAN2020:16:49:00
2 1 02JAN2020:16:49:00
2 0 23JUL2020:16:49:00
2 1 25JUL2020:16:49:00
2 1 02AUG2020:16:49:00
3 0 01JAN2020:16:49:00
3 0 03JUL2020:16:49:00
3 1 13JUL2020:16:49:00
3 1 23JUL2020:16:49:00
3 0 24JUL2020:16:49:00
3 1 25JUL2020:16:49:00
;

data want;
   set have;
   by ID Revoke notsorted;
   if Revoke = 0 then NewDate = .;
   if Revoke = 1 and first.Revoke then NewDate = Date;
   retain NewDate;
   format NewDate datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Nov 2021 21:50:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-Earliest-date-by-multiple-Keys/m-p/781396#M249032</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-11-19T21:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: Returning Earliest date by multiple Keys</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-Earliest-date-by-multiple-Keys/m-p/781400#M249034</link>
      <description>Retain is what I was forgetting about thank you I knew I was over complicating this!</description>
      <pubDate>Fri, 19 Nov 2021 21:51:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-Earliest-date-by-multiple-Keys/m-p/781400#M249034</guid>
      <dc:creator>Krueger1</dc:creator>
      <dc:date>2021-11-19T21:51:57Z</dc:date>
    </item>
  </channel>
</rss>

