<?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: Finding Earliest time with Separate Month Year Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-Earliest-time-with-Separate-Month-Year-Variables/m-p/580170#M164780</link>
    <description>&lt;P&gt;Alternatively try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array event(*) E1 E2;
array months(*) M1 M2;
array years(*) Y1 Y2;
do i = 1 to dim(event);
if event(i) ne . then e=vname(event(i));
if month(i) ne . then m=months(i);
if year(i) ne . then y=years(i);
output;
end;
run;

proc sort data=want;
by id y m;
where y ne .;
run;

data want2;
set want;
by id y m ;
if first.id;
keep id e m y;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 09 Aug 2019 15:15:05 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2019-08-09T15:15:05Z</dc:date>
    <item>
      <title>Finding Earliest time with Separate Month Year Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Earliest-time-with-Separate-Month-Year-Variables/m-p/580130#M164766</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I currently have a data set of events with the month and year recorded for each event. For each person i want to find which event happens first and then find the year and month of this event.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Example data&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp;E1&amp;nbsp; &amp;nbsp;M1&amp;nbsp; &amp;nbsp; &amp;nbsp; Y1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; E2&amp;nbsp; &amp;nbsp;M2&amp;nbsp; &amp;nbsp; &amp;nbsp; Y2&amp;nbsp;&lt;/P&gt;&lt;P&gt;001&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7&amp;nbsp; &amp;nbsp; 1999&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;002&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2004&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2001&lt;/P&gt;&lt;P&gt;003&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp;2006&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 11&amp;nbsp; &amp;nbsp; &amp;nbsp; 2006&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;etc...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Want&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FirstE&amp;nbsp; &amp;nbsp; &amp;nbsp; FirstMonth&amp;nbsp; &amp;nbsp;FirstYear&lt;/P&gt;&lt;P&gt;E1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1999&lt;/P&gt;&lt;P&gt;E2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2001&lt;/P&gt;&lt;P&gt;E1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2006&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I have currently been trying i cant get to work so any suggestions would be really helpful!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data want;&lt;BR /&gt; set have;&lt;BR /&gt;
   Year = min(Y1, Y2);

   array Years (*) Y1 Y2;
   array Months (*) M1 M2;

  	if Year = Y1 = Y2 then &lt;BR /&gt;                FirstE = vname(Months[whichn(smallest(1,of Months[*]), of Months[*])]); else
	if Y1 ^= Y2 then &lt;BR /&gt;                FirstE = vname(Years[whichn(smallest(1,of Years[*]), of Years[*])]);&lt;BR /&gt;&lt;BR /&gt;     if FirstE = "E1" then do;&lt;BR /&gt;                   FirstMonth = M1; FirstYear = Y1; end; else&lt;BR /&gt;     if FirstE = "E2" then do;&lt;BR /&gt;                   FirstMonth = M2; FirstYear = Y2; end;&lt;BR /&gt;RUN;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Cydney&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 14:13:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Earliest-time-with-Separate-Month-Year-Variables/m-p/580130#M164766</guid>
      <dc:creator>CydneyLB</dc:creator>
      <dc:date>2019-08-09T14:13:58Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Earliest time with Separate Month Year Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Earliest-time-with-Separate-Month-Year-Variables/m-p/580158#M164774</link>
      <description>&lt;P&gt;Use function mdy() and take proper care of missing values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
d1 = coalesce(mdy(M1, 1, Y1), constant("BIG"));
d2 = coalesce(mdy(M2, 1, Y2), constant("BIG"));
if d1 &amp;lt;= d2 then do;
    FirstE = "E1";
    firstYear = Y1;
    FirstMonth = M1;
    end;
 else if d1 &amp;gt; d2 then do;
    FirstE = "E2";
    firstYear = Y2;
    FirstMonth = M2;
    end;
drop d1 d2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 14:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Earliest-time-with-Separate-Month-Year-Variables/m-p/580158#M164774</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-08-09T14:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Earliest time with Separate Month Year Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Earliest-time-with-Separate-Month-Year-Variables/m-p/580162#M164776</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for commenting!&lt;/P&gt;&lt;P&gt;I was trying to avoid creating a date variable (for later calculations) but that will work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Cydney&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 15:00:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Earliest-time-with-Separate-Month-Year-Variables/m-p/580162#M164776</guid>
      <dc:creator>CydneyLB</dc:creator>
      <dc:date>2019-08-09T15:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Earliest time with Separate Month Year Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Earliest-time-with-Separate-Month-Year-Variables/m-p/580167#M164778</link>
      <description>&lt;P&gt;FWIW&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
Input ID $     E1   M1      Y1          E2   M2      Y2 ;
cards;
001    1       7    1999        0      .         .
002    1       1     2004       1       9       2001
003    1       3     2006       1      11      2006
;

data temp;
 set have;
 array t(2,3) E1--y2;
 array j FirstE      FirstMonth   FirstYear;
 do _i=1 to 2;
  call missing(temp);
  do _k=1 to 3;
   j(_k)=t(_i,_k);
  end;
  if n(of j(*))=dim(j) then temp=mdy(firstmonth,1,firstyear);
  output;
 end;
keep first: temp id;
run;
proc sql;
create table want(drop=temp) as
select *
from temp
group by id
having temp=min(temp);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Aug 2019 15:10:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Earliest-time-with-Separate-Month-Year-Variables/m-p/580167#M164778</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-09T15:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Earliest time with Separate Month Year Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Earliest-time-with-Separate-Month-Year-Variables/m-p/580170#M164780</link>
      <description>&lt;P&gt;Alternatively try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array event(*) E1 E2;
array months(*) M1 M2;
array years(*) Y1 Y2;
do i = 1 to dim(event);
if event(i) ne . then e=vname(event(i));
if month(i) ne . then m=months(i);
if year(i) ne . then y=years(i);
output;
end;
run;

proc sort data=want;
by id y m;
where y ne .;
run;

data want2;
set want;
by id y m ;
if first.id;
keep id e m y;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Aug 2019 15:15:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Earliest-time-with-Separate-Month-Year-Variables/m-p/580170#M164780</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-08-09T15:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Earliest time with Separate Month Year Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Earliest-time-with-Separate-Month-Year-Variables/m-p/580488#M164905</link>
      <description>&lt;P&gt;This solution is nice and simple thanks Jag&amp;nbsp;&lt;img id="smileyvery-happy" class="emoticon emoticon-smileyvery-happy" src="https://communities.sas.com/i/smilies/16x16_smiley-very-happy.png" alt="Smiley Very Happy" title="Smiley Very Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2019 09:02:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Earliest-time-with-Separate-Month-Year-Variables/m-p/580488#M164905</guid>
      <dc:creator>CydneyLB</dc:creator>
      <dc:date>2019-08-12T09:02:09Z</dc:date>
    </item>
  </channel>
</rss>

