<?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: Find the array of unique type and valid date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-the-array-of-unique-type-and-valid-date/m-p/963516#M375356</link>
    <description>&lt;P&gt;Questions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;What do you mean by "most current"?&lt;/LI&gt;
&lt;LI&gt;I don't think I understand what you mean by "unique".&amp;nbsp; Can you provide a more complete explanation?&lt;/LI&gt;
&lt;LI&gt;Why does your code provide for 10 TYPE variables in WANT, when there are only 8 TYPE variables in HAVE?&lt;/LI&gt;
&lt;/OL&gt;</description>
    <pubDate>Sat, 05 Apr 2025 03:17:00 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2025-04-05T03:17:00Z</dc:date>
    <item>
      <title>Find the array of unique type and valid date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-array-of-unique-type-and-valid-date/m-p/963500#M375346</link>
      <description>&lt;P&gt;Below is an example of data I have.&amp;nbsp; I want to find an array of unique types based on the startmonth and startyear.&amp;nbsp; I want to find an array of valid end dates for each unique type.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&amp;nbsp;HAVE;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; input caseid startmonth961 startyear961 startmonth962 startyear962 startmonth963 startyear963 startmonth964 startyear964&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; startmonth981 startyear981 startmonth982 startyear982 startmonth983 startyear983 startmonth984 startyear984&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; endmonth961 endyear961 endmonth962 endyear962 endmonth963 endyear963 endmonth964 endyear964&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; endmonth981 endyear981 endmonth982 endyear82&amp;nbsp; endmonth983 endyear983 endmonth984 endyear984&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;type961 type962 type963 type964 type981 type982 type983 type984;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 1 1995 5 1996 10 1997 -4 -4 1 1998 10 1997 -4 -4 -4 -4 1 1995 5 1988 -4 -4 -4 -4 -4 -4 12 1997 -4 -4 -4 -4 6 8 1 . 6 1 . .&lt;/P&gt;&lt;P&gt;&amp;nbsp;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my code.&amp;nbsp; I was able to find unique types.&amp;nbsp; I'm unable to get the valid end dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;data mycode;&lt;/DIV&gt;&lt;DIV&gt;set have;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;array train type961-type964 type981-type984;&lt;/P&gt;&lt;P&gt;array start_mo startmonth961-startmonth964 startmonth981-startmonth984;&lt;/P&gt;&lt;P&gt;array start_yr startyear961-startyear964 startyear981-startyear984;&lt;/P&gt;&lt;P&gt;array end_mo endmonth961-endmonth964 endmonth981 - endmonth984;&lt;/P&gt;&lt;P&gt;array end_yr endyear961-endyear964 endyear981 - endyear984;&lt;/P&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;array unique u01 - u10;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;array stmo_unique stmo01-stmo10;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;array styr_unique styr01-styr10;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;array m&amp;nbsp; m01-m10;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;array endmo_unique endmo01-endmo10;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;array endyr_unique endyr01-endyr10;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;unique_count = 0;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;do i =1 to dim(train);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if (train{i} ne .) then do;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;match_found = 0;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;do j= 1 to unique_count;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if (train{i} = unique{j} and start_mo{i} = stmo_unique{j} and start_yr{i} = styr_unique{j}) then do;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if end_mo{i} ne -4 and end_yr{i} ne -4 then do;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if endmo_unique{j} =-4 and endyr_unique{j}=-4 or (end_yr{i}&amp;gt;endyr_unique{j}) or (end_yr{i} = endyr_unique{j} and end_mo{i} &amp;gt; endmo_unique{j}) then do;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;endmo_unique{j} =end_mo{i};&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;endyr_unique{j}=end_yr{i};&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;match_found = 1;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;m{j} = 1;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;leave;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if (match_found = 0) then do;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;unique_count + 1;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;unique{unique_count} = train{i};&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;stmo_unique{unique_count}=start_mo{i};&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;styr_unique{unique_count}=start_yr{i};&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;endmo_unique{unique_count}=end_mo{i};&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;endyr_unique{unique_count}=end_yr{i};&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;keep caseid&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I want.&amp;nbsp; If there are duplicates of types, some have invalid end dates and some valid end dates, then the end date should be the most current valid end date.&amp;nbsp; If duplicates have all valid end dates, then it should be the most current valid end dates.&amp;nbsp; If duplicates have all invalid end dates, then the end date should be invalid.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If type is unique, then assign its own end dates (it could be valid or invalid).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, type963 and type982 have same type (1) and same start month &amp;amp; year (10/1997).&amp;nbsp; However, endmonth963 (-4) and endyear963 (-4) differ from endmonth982 (12) and endyear1982(1997).&amp;nbsp; So, the third unique type should be:&amp;nbsp; u03 =1, stmo03=10, styr03=1997, endyr03=12, endyr03=1997, m03 =1;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;input id u01 - u5 stmo01-stmo5 styr01-styr5 endmo01-endmo05 endyr01-endyr5 m01-m5;&lt;BR /&gt;datalines;&lt;BR /&gt;1 6 8 1 6 . 1 5 10 1 . 1995 1996 1997 1998 . 1 5 12 -4 . 1995 1988 1997 -4 . . . 1 . .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 20:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-array-of-unique-type-and-valid-date/m-p/963500#M375346</guid>
      <dc:creator>kk13</dc:creator>
      <dc:date>2025-04-04T20:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Find the array of unique type and valid date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-array-of-unique-type-and-valid-date/m-p/963508#M375351</link>
      <description>&lt;P&gt;Is this an easier problem to think about if your data are vertical?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vert;
set have;
length num 5 startmo startyr endmo endyr type 8;
array sm {*} startmonth:;
array sy {*} startyear:;
array em {*} endmonth:;
array ey {*} endyear:;
array tp {*} type:;
do i=1 to dim(sm);
	num=substr(vname(sm[i]),anydigit(vname(sm[i])))*1;
	startmo=sm[i];
	startyr=sy[i];
	endmo=em[i];
	endyr=ey[i];
	type=tp[i];
	output;
end;
keep caseid num startmo startyr endmo endyr type;
run;

proc print data=vert width=min; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="quickbluefish_0-1743813278154.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105954i7714C46E3C4068EF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="quickbluefish_0-1743813278154.png" alt="quickbluefish_0-1743813278154.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Apr 2025 00:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-array-of-unique-type-and-valid-date/m-p/963508#M375351</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-04-05T00:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Find the array of unique type and valid date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-array-of-unique-type-and-valid-date/m-p/963516#M375356</link>
      <description>&lt;P&gt;Questions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;What do you mean by "most current"?&lt;/LI&gt;
&lt;LI&gt;I don't think I understand what you mean by "unique".&amp;nbsp; Can you provide a more complete explanation?&lt;/LI&gt;
&lt;LI&gt;Why does your code provide for 10 TYPE variables in WANT, when there are only 8 TYPE variables in HAVE?&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Sat, 05 Apr 2025 03:17:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-array-of-unique-type-and-valid-date/m-p/963516#M375356</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2025-04-05T03:17:00Z</dc:date>
    </item>
  </channel>
</rss>

