<?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 recode the dates for some observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-recode-the-dates-for-some-observations/m-p/730894#M227655</link>
    <description>&lt;P&gt;If you just want to use the first last_date per key based on sort order of your source data then below one way to go.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
  input ID first_date :mmddyy10. last_date :mmddyy10. edu class;
  format first_date mmddyy10.;
  format last_date mmddyy10.;
  datalines;
1 02-01-2015  02-01-2015  3  3 
1 02-01-2015  02-12-2015  3  1
1 02-01-2015  02-16-2015  3  3
1 02-01-2015  03-01-2015  3  3
1 08-20-2015  09-01-2015  3  3
1 10-06-2015  10-09-2015  2  1
2 10-19-2017  10-19-2017  1  1 
2 10-19-2017  10-21-2017  3  1
2 10-19-2017  11-05-2017  2  2
2 10-19-2017  11-11-2017  1  1
2 10-19-2017  12-22-2017  1  1
2 12-25-2017  12-25-2017  3  2
;

data want;
  if _n_=1 then
    do;
      dcl hash h1(dataset:'have(keep=id first_date edu class last_date)');
      h1.defineKey('id','first_date','edu','class');
      h1.defineData('last_date');
      h1.defineDone();
    end;

  set have;
  h1.find();
run;

data expected;
  input ID first_date :mmddyy10. last_date :mmddyy10. edu class;
  format first_date mmddyy10.;
  format last_date mmddyy10.;
  datalines;
1 02-01-2015 02-01-2015 3 3
1 02-01-2015 02-12-2015 3 1
1 02-01-2015 02-01-2015 3 3
1 02-01-2015 02-01-2015 3 3
1 08-20-2015 09-01-2015 3 3
1 10-06-2015 10-09-2015 2 1
2 10-19-2017 10-19-2017 1 1
2 10-19-2017 10-21-2017 3 1
2 10-19-2017 11-05-2017 2 2
2 10-19-2017 10-19-2017 1 1
2 10-19-2017 10-19-2017 1 1
2 12-25-2017 12-25-2017 3 2
;

proc compare
  data=want
  comp=expected
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;While loading the SAS hash table without option "multidata" SAS will only pick the first instance of a unique key combination and that's what the lookup using the find() method will return.&lt;/P&gt;</description>
    <pubDate>Fri, 02 Apr 2021 01:05:08 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2021-04-02T01:05:08Z</dc:date>
    <item>
      <title>How to recode the dates for some observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-recode-the-dates-for-some-observations/m-p/730890#M227652</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Hi SAS Pros,&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;I have a dataset like showed below. &lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input ID first_date :mmddyy10. last_date :mmddyy10. edu class;
format first_date mmddyy10.;
format last_date mmddyy10.;
datalines;
1 02-01-2015  02-01-2015  3  3 
1 02-01-2015  02-12-2015  3  1
1 02-01-2015  02-16-2015  3  3
1 02-01-2015  03-01-2015  3  3
1 08-20-2015  09-01-2015  3  3
1 10-06-2015  10-09-2015  2  1
2 10-19-2017  10-19-2017  1  1 
2 10-19-2017  10-21-2017  3  1
2 10-19-2017  11-05-2017  2  2
2 10-19-2017  11-11-2017  1  1
2 10-19-2017  12-22-2017  1  1
2 12-25-2017  12-25-2017  3  2
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;I would like to recode the last dates if the records&amp;nbsp;under the same ID match on&amp;nbsp;ID, first_date, edu, and&amp;nbsp;class, with only last dates are different.&amp;nbsp;One of these set of records has a first date and last date are the same (i.e. the first record for each ID). The I would like to enter the date&amp;nbsp;of the record with same first and last dates (i.e. 02-01-2015 for ID=1 and 10-19-2017 for ID=2) for the last dates for those records match on&amp;nbsp;ID, first_date, edu, and&amp;nbsp;class under the same ID. &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;If the records under the same ID are different&amp;nbsp;in any of ID, first_date, edu, and&amp;nbsp;class, then just leave as them own, regardless first date is different or the same as the last date. &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The Want data is also post below.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;02&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;01&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2015&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;02&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;01&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2015&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;02&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;01&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2015&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;02&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;12&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2015&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;02&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;01&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2015&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;02&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;01&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2015&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;02&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;01&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2015&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;02&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;01&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2015&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;08&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;20&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2015&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;09&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;01&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2015&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;06&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2015&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;09&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2015&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;19&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2017&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;19&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2017&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;19&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2017&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;21&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2017&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;19&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2017&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;11&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;05&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2017&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;19&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2017&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;19&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2017&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;19&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2017&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;19&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2017&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;12&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;25&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2017&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;12&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;25&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2017&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Thank you very much for any help!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Best regards,&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;C&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Apr 2021 00:26:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-recode-the-dates-for-some-observations/m-p/730890#M227652</guid>
      <dc:creator>CynthiaWei</dc:creator>
      <dc:date>2021-04-02T00:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to recode the dates for some observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-recode-the-dates-for-some-observations/m-p/730894#M227655</link>
      <description>&lt;P&gt;If you just want to use the first last_date per key based on sort order of your source data then below one way to go.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
  input ID first_date :mmddyy10. last_date :mmddyy10. edu class;
  format first_date mmddyy10.;
  format last_date mmddyy10.;
  datalines;
1 02-01-2015  02-01-2015  3  3 
1 02-01-2015  02-12-2015  3  1
1 02-01-2015  02-16-2015  3  3
1 02-01-2015  03-01-2015  3  3
1 08-20-2015  09-01-2015  3  3
1 10-06-2015  10-09-2015  2  1
2 10-19-2017  10-19-2017  1  1 
2 10-19-2017  10-21-2017  3  1
2 10-19-2017  11-05-2017  2  2
2 10-19-2017  11-11-2017  1  1
2 10-19-2017  12-22-2017  1  1
2 12-25-2017  12-25-2017  3  2
;

data want;
  if _n_=1 then
    do;
      dcl hash h1(dataset:'have(keep=id first_date edu class last_date)');
      h1.defineKey('id','first_date','edu','class');
      h1.defineData('last_date');
      h1.defineDone();
    end;

  set have;
  h1.find();
run;

data expected;
  input ID first_date :mmddyy10. last_date :mmddyy10. edu class;
  format first_date mmddyy10.;
  format last_date mmddyy10.;
  datalines;
1 02-01-2015 02-01-2015 3 3
1 02-01-2015 02-12-2015 3 1
1 02-01-2015 02-01-2015 3 3
1 02-01-2015 02-01-2015 3 3
1 08-20-2015 09-01-2015 3 3
1 10-06-2015 10-09-2015 2 1
2 10-19-2017 10-19-2017 1 1
2 10-19-2017 10-21-2017 3 1
2 10-19-2017 11-05-2017 2 2
2 10-19-2017 10-19-2017 1 1
2 10-19-2017 10-19-2017 1 1
2 12-25-2017 12-25-2017 3 2
;

proc compare
  data=want
  comp=expected
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;While loading the SAS hash table without option "multidata" SAS will only pick the first instance of a unique key combination and that's what the lookup using the find() method will return.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Apr 2021 01:05:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-recode-the-dates-for-some-observations/m-p/730894#M227655</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-02T01:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to recode the dates for some observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-recode-the-dates-for-some-observations/m-p/730901#M227657</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the codes. However, they just happened to be the first records. It is not necessary to be the first record with the same first and last date. I just list them like that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want is to meet the conditions I mentioned in the first thread.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;C&lt;/P&gt;</description>
      <pubDate>Fri, 02 Apr 2021 02:06:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-recode-the-dates-for-some-observations/m-p/730901#M227657</guid>
      <dc:creator>CynthiaWei</dc:creator>
      <dc:date>2021-04-02T02:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to recode the dates for some observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-recode-the-dates-for-some-observations/m-p/730903#M227658</link>
      <description>&lt;P&gt;The condition for changing last_date is met and the code returns the desired data as posted by you.&lt;/P&gt;
&lt;P&gt;The last_date used will be taken from the first occurrence of the key combination encountered in the data.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Apr 2021 02:16:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-recode-the-dates-for-some-observations/m-p/730903#M227658</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-02T02:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to recode the dates for some observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-recode-the-dates-for-some-observations/m-p/730905#M227659</link>
      <description>&lt;P&gt;I understand your task as follows: if a given combination of id*first_date*edu*class has one record do nothing, i.e. leave the last_date value as is.&amp;nbsp; But if that combination has more than one record, then assign last_date=first_date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This can be done by passing through each ID twice.&amp;nbsp; The first pass to count the frequency of a given id*first_date*edu*class, and the second pass to output the record with last_date modified if needed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
  input ID first_date :mmddyy10. last_date :mmddyy10. edu class;
  format first_date mmddyy10.;
  format last_date mmddyy10.;
  datalines;
1 02-01-2015  02-01-2015  3  3 
1 02-01-2015  02-12-2015  3  1
1 02-01-2015  02-16-2015  3  3
1 02-01-2015  03-01-2015  3  3
1 08-20-2015  09-01-2015  3  3
1 10-06-2015  10-09-2015  2  1
2 10-19-2017  10-19-2017  1  1 
2 10-19-2017  10-21-2017  3  1
2 10-19-2017  11-05-2017  2  2
2 10-19-2017  11-11-2017  1  1
2 10-19-2017  12-22-2017  1  1
2 12-25-2017  12-25-2017  3  2
;

data want;
  set have (in=firstpass)  have (in=secondpass);
  by id;

  array _n_fdates {%sysevalf("01jan2015"d):%sysevalf("31dec2017"d),3,3} _temporary_;
  if first.id then call missing(of _n_fdates{*});

  if firstpass then _n_fdates{first_date,edu,class}+1;
  if secondpass;
  if _n_fdates{first_date,edu,class}&amp;gt;1 then last_date=first_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The array _N_FDATES is a 3-dimensional array.&amp;nbsp; The first dimension has a lower bound of "01jan2015"d and an upper bound of "31dec2017"d, to cover the expected range of first_date values.&amp;nbsp; Change it to cover the actual domain of your data.&amp;nbsp; The second dimension goes from 1 to 3 to cover EDU values, and the third also goes from 1 to 3 to cover CLASS values.&amp;nbsp; They can be changed to other integer ranges too, if needed.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This program assumes the data are sorted by ID, but can be any order within ID.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Apr 2021 03:04:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-recode-the-dates-for-some-observations/m-p/730905#M227659</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-04-02T03:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to recode the dates for some observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-recode-the-dates-for-some-observations/m-p/733923#M228688</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much for the code! I was not able to work on this project in the past weeks so sorry for my late reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think your understanding is quite close to my task. I think there is one criterion&amp;nbsp;needs to add here: if a given combination of &lt;U&gt;id*first_date*edu*class&lt;/U&gt; has one record do nothing, i.e. leave the last_date value as is.&amp;nbsp; But if that combination has more than one record &lt;U&gt;&lt;STRONG&gt;and one record has a date difference of 0&lt;/STRONG&gt;&lt;/U&gt;, then assign last_date=first_date for the rest.&amp;nbsp;So, if a given combination of id*first_date*edu*class&amp;nbsp;has more than one record but&amp;nbsp;each record&amp;nbsp;has a date difference &amp;gt;0 and none of the records has a date difference of 0 within this ID, then leave them. Examples like follows:(there is no record like "5&amp;nbsp;&amp;nbsp; 8-19-2017&amp;nbsp; 8-19-2017&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1" for this person)&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; First_date&amp;nbsp;&amp;nbsp; Last_date&amp;nbsp;&amp;nbsp;&amp;nbsp; EDU&amp;nbsp;&amp;nbsp; Class&lt;/P&gt;
&lt;P&gt;5&amp;nbsp;&amp;nbsp; 8-19-2017&amp;nbsp; 11-11-2017&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;5&amp;nbsp;&amp;nbsp; 8-19-2017&amp;nbsp; 12-22-2017&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please advice me what the code look like when incorporating the above situation. I apologize for not specifying this before.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if the variables that are going to be&amp;nbsp;involved in a given combination are varA, varB, varC, varD, varE, varF and varG, I just need to put all of them in the "{}" in the if then statement, right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 21:02:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-recode-the-dates-for-some-observations/m-p/733923#M228688</guid>
      <dc:creator>CynthiaWei</dc:creator>
      <dc:date>2021-04-14T21:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to recode the dates for some observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-recode-the-dates-for-some-observations/m-p/734093#M228722</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266374"&gt;@CynthiaWei&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much for the code! I was not able to work on this project in the past weeks so sorry for my late reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think your understanding is quite close to my task. I think there is one criterion&amp;nbsp;needs to add here: if a given combination of &lt;U&gt;id*first_date*edu*class&lt;/U&gt; has one record do nothing, i.e. leave the last_date value as is.&amp;nbsp; But if that combination has more than one record &lt;U&gt;&lt;STRONG&gt;and one record has a date difference of 0&lt;/STRONG&gt;&lt;/U&gt;, then assign last_date=first_date for the rest.&amp;nbsp;So, if a given combination of id*first_date*edu*class&amp;nbsp;has more than one record but&amp;nbsp;each record&amp;nbsp;has a date difference &amp;gt;0 and none of the records has a date difference of 0 within this ID, then leave them. Examples like follows:(there is no record like "5&amp;nbsp;&amp;nbsp; 8-19-2017&amp;nbsp; 8-19-2017&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1" for this person)&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; First_date&amp;nbsp;&amp;nbsp; Last_date&amp;nbsp;&amp;nbsp;&amp;nbsp; EDU&amp;nbsp;&amp;nbsp; Class&lt;/P&gt;
&lt;P&gt;5&amp;nbsp;&amp;nbsp; 8-19-2017&amp;nbsp; 11-11-2017&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;5&amp;nbsp;&amp;nbsp; 8-19-2017&amp;nbsp; 12-22-2017&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Could you please advice me what the code look like when incorporating the above situation. I apologize for not specifying this before.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So instead of assigning last_date=first_date for all combinations that have multiple records, as I had programmed before, just do it for all combinations that have multiple records, of which at least one already has last_date=first_date:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In that case then during the first pass, the program should still count records by combination.&amp;nbsp; But in addition, if any record has first_date=last_date, then add (say) 1,000 to the count.&amp;nbsp; I choose 1,000 because I assume no combination is likely to have near 1,000 records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This means:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;A single record would have count=1 or 1,001&lt;/LI&gt;
&lt;LI&gt;Multiple records would have counts 2,3,4,...&amp;nbsp; &amp;nbsp; or 1,002+&lt;/LI&gt;
&lt;LI&gt;Therefore, during the second pass, only count&amp;gt;1,001 requires assigning last_date=first_date&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have (in=firstpass)  have (in=secondpass);
  by id;

  array _n_fdates {%sysevalf("01jan2015"d):%sysevalf("31dec2017"d),3,3} _temporary_;
  if first.id then call missing(of _n_fdates{*});

  if firstpass then do;
    _n_fdates{first_date,edu,class}+1;
    if first_date=last_date then _n_fdates{first_date,edu,class}+1000;
  end;
  if secondpass;
  if _n_fdates{first_date,edu,class}&amp;gt;1001 then last_date=first_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if the variables that are going to be&amp;nbsp;involved in a given combination are varA, varB, varC, varD, varE, varF and varG, I just need to put all of them in the "{}" in the if then statement, right?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In short yes.&amp;nbsp; Make provision for each variable in the array statement, and then use those variable names as the array indexes in the subsequent statements.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 04:28:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-recode-the-dates-for-some-observations/m-p/734093#M228722</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-04-15T04:28:41Z</dc:date>
    </item>
  </channel>
</rss>

