<?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 categorical var that is true as of max of a date var in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Choosing-categorical-var-that-is-true-as-of-max-of-a-date-var/m-p/255650#M48862</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with an ID, two date vars, and a categorical variable:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; Date1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Date2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Categ_var&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/2010 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3/5/2010 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abc&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;10/11/2010 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10/12/2010 &amp;nbsp; &amp;nbsp; &amp;nbsp;def&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;1/5/2011 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5/10/2011 &amp;nbsp; &amp;nbsp; &amp;nbsp; ghi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is a summary dataset that will give me for each ID the min Date1, the max Date2, and the value of Categ_var that holds at the time of max(Date2), like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; min_Date1 &amp;nbsp;max_Date2 &amp;nbsp;Categ_var&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; 1/1/2010 &amp;nbsp; &amp;nbsp; 5/10/2011 &amp;nbsp; &amp;nbsp;ghi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was planning to do the min of Date1 and max of Date2 with a proc sql step, but I wasn't sure how to integrate the categ_var part.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 09 Mar 2016 20:44:23 GMT</pubDate>
    <dc:creator>Walternate</dc:creator>
    <dc:date>2016-03-09T20:44:23Z</dc:date>
    <item>
      <title>Choosing categorical var that is true as of max of a date var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choosing-categorical-var-that-is-true-as-of-max-of-a-date-var/m-p/255650#M48862</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with an ID, two date vars, and a categorical variable:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; Date1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Date2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Categ_var&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/2010 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3/5/2010 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abc&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;10/11/2010 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10/12/2010 &amp;nbsp; &amp;nbsp; &amp;nbsp;def&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;1/5/2011 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5/10/2011 &amp;nbsp; &amp;nbsp; &amp;nbsp; ghi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is a summary dataset that will give me for each ID the min Date1, the max Date2, and the value of Categ_var that holds at the time of max(Date2), like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; min_Date1 &amp;nbsp;max_Date2 &amp;nbsp;Categ_var&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; 1/1/2010 &amp;nbsp; &amp;nbsp; 5/10/2011 &amp;nbsp; &amp;nbsp;ghi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was planning to do the min of Date1 and max of Date2 with a proc sql step, but I wasn't sure how to integrate the categ_var part.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2016 20:44:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choosing-categorical-var-that-is-true-as-of-max-of-a-date-var/m-p/255650#M48862</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2016-03-09T20:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing categorical var that is true as of max of a date var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choosing-categorical-var-that-is-true-as-of-max-of-a-date-var/m-p/255658#M48867</link>
      <description>If your dag is not huge, you can join the min-max result with your original data. &lt;BR /&gt;Hope you don't have duplicates on date2.</description>
      <pubDate>Wed, 09 Mar 2016 21:18:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choosing-categorical-var-that-is-true-as-of-max-of-a-date-var/m-p/255658#M48867</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-03-09T21:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing categorical var that is true as of max of a date var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choosing-categorical-var-that-is-true-as-of-max-of-a-date-var/m-p/255659#M48868</link>
      <description>Damn autocorrect. "If your data is not huge", should it read...</description>
      <pubDate>Wed, 09 Mar 2016 21:19:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choosing-categorical-var-that-is-true-as-of-max-of-a-date-var/m-p/255659#M48868</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-03-09T21:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing categorical var that is true as of max of a date var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choosing-categorical-var-that-is-true-as-of-max-of-a-date-var/m-p/255683#M48878</link>
      <description>&lt;P&gt;Is it possible to have ties for the max date?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2016 22:31:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choosing-categorical-var-that-is-true-as-of-max-of-a-date-var/m-p/255683#M48878</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-09T22:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing categorical var that is true as of max of a date var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choosing-categorical-var-that-is-true-as-of-max-of-a-date-var/m-p/255685#M48880</link>
      <description>&lt;P&gt;I think you may want something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway;
   class id;
   var date1 date2;
   output out=want (drop= _;) min(date1)=date1 max(date2)=date2 maxid(date2(categ_var))=Categ_var;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Mar 2016 22:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choosing-categorical-var-that-is-true-as-of-max-of-a-date-var/m-p/255685#M48880</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-03-09T22:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing categorical var that is true as of max of a date var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choosing-categorical-var-that-is-true-as-of-max-of-a-date-var/m-p/255710#M48889</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID     Date1  : mmddyy10.      Date2   : mmddyy10.    Categ_var $;
format Date1      Date2    mmddyy10.;
cards;
1      1/1/2010            3/5/2010          abc
1      10/11/2010        10/12/2010      def
1      1/5/2011             5/10/2011       ghi
;
run;
proc sort data=have;by id date2;run;
data want;
 set have;
 by id;
 if first.id then min_date1=999999;
 retain min_date1;
 min_date1=min(min_date1,date1);
 if last.id then do; max_date2=date2;output;end;
 drop date1 date2;
 format min_date1 max_date2 mmddyy10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Mar 2016 01:45:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choosing-categorical-var-that-is-true-as-of-max-of-a-date-var/m-p/255710#M48889</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-10T01:45:54Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing categorical var that is true as of max of a date var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choosing-categorical-var-that-is-true-as-of-max-of-a-date-var/m-p/257131#M49337</link>
      <description>&lt;P&gt;Thank you, this solution seems to work. If I had in addition a numerical var (Num_var) and I wanted the sum of num_var for each value of ID in addition to the rest of it, could I do that with just a slight alteration to this code?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2016 20:16:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choosing-categorical-var-that-is-true-as-of-max-of-a-date-var/m-p/257131#M49337</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2016-03-16T20:16:48Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing categorical var that is true as of max of a date var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choosing-categorical-var-that-is-true-as-of-max-of-a-date-var/m-p/257189#M49349</link>
      <description>&lt;P&gt;Sure.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID     Date1  : mmddyy10.      Date2   : mmddyy10.    Categ_var $ Num_var;
format Date1      Date2    mmddyy10.;
cards;
1      1/1/2010            3/5/2010          abc 1
1      10/11/2010        10/12/2010      def 2
1      1/5/2011             5/10/2011       ghi 3
;
run;
proc sort data=have;by id date2;run;
data want;
 set have;
 by id;
 if first.id then do;min_date1=999999;sum=0;end;
 retain min_date1;
 min_date1=min(min_date1,date1);sum+Num_var;
 if last.id then do; max_date2=date2;output;end;
 drop date1 date2 Num_var;
 format min_date1 max_date2 mmddyy10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Mar 2016 00:52:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choosing-categorical-var-that-is-true-as-of-max-of-a-date-var/m-p/257189#M49349</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-17T00:52:02Z</dc:date>
    </item>
  </channel>
</rss>

