<?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: Identifying the variable associated with the first.date for a series of dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-variable-associated-with-the-first-date-for-a/m-p/724678#M224999</link>
    <description>&lt;P&gt;One could use your approach but much more simply:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
  set test;
  if int_date1=min(of int_date:) then int=1; else
  if int_date2=min(of int_date:) then int=2; else
  if int_date3=min(of int_date:) then int=3; else
  if int_date4=min(of int_date:) then int=4;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or more generally:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
  set test;
  int=whichn(min(of int_datet:),of min_date:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The latter assumes your variables are named, int_date1, int_date2, ... int_date4, in that order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The nice thing about the latter is that it accommodates any number of consecutively named INT_DATE variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One issue, for both techniques.&amp;nbsp; If there is a tie for minimum(earliest) date, then this always chooses the leftmost.&lt;/P&gt;</description>
    <pubDate>Mon, 08 Mar 2021 22:17:37 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2021-03-08T22:17:37Z</dc:date>
    <item>
      <title>Identifying the variable associated with the first.date for a series of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-variable-associated-with-the-first-date-for-a/m-p/724628#M224977</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I would like to identify the first occurrence of an intervention for 4 different interventions. In other words, of the 4 interventions which one occurred first. I have included sample variables and code. thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;sample data set:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;patient1&amp;nbsp; &amp;nbsp;intervention1 &amp;nbsp;int1_date &amp;nbsp;intervention2&amp;nbsp; int2_date &amp;nbsp;intervention3&amp;nbsp; int3_date &amp;nbsp;intervention4 &amp;nbsp;int4_date&lt;/P&gt;&lt;P&gt;patient2&amp;nbsp; ............&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test2;&lt;/P&gt;&lt;P&gt;set test;&lt;/P&gt;&lt;P&gt;by ID;&lt;/P&gt;&lt;P&gt;if (int1_date &amp;lt; int2_date and int1_date &amp;lt; int3_date and int1_date &amp;lt; int4_date) then int =1;&lt;/P&gt;&lt;P&gt;if (int2_date &amp;lt; int1_date and int2_date &amp;lt; int3_date and int2_date &amp;lt; int4_date) then int =2;&lt;/P&gt;&lt;P&gt;if (int3_date &amp;lt; int1_date and int3_date &amp;lt;int2_date and int3_date &amp;lt; int4_date) then int =3;&lt;/P&gt;&lt;P&gt;if (int4_date&amp;lt; int1_date and int4_date &amp;lt;int2_date and int4_date &amp;lt; int3_date) then int =5;&lt;/P&gt;&lt;P&gt;else int = 5;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 20:14:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-variable-associated-with-the-first-date-for-a/m-p/724628#M224977</guid>
      <dc:creator>cschmidt</dc:creator>
      <dc:date>2021-03-08T20:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the variable associated with the first.date for a series of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-variable-associated-with-the-first-date-for-a/m-p/724639#M224981</link>
      <description>&lt;P&gt;Transpose to a long dataset, sort by patient and date, and then extract the information at first.patient from _name_.&lt;/P&gt;
&lt;P&gt;Maxim 19: Long Beats Wide.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 20:30:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-variable-associated-with-the-first-date-for-a/m-p/724639#M224981</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-08T20:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the variable associated with the first.date for a series of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-variable-associated-with-the-first-date-for-a/m-p/724640#M224982</link>
      <description>&lt;P&gt;Arrays, and WHICHN() are the key items here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
set test1;

array _dates(*) int1_date int2_date ....;
array _ints(*) intervention1-intervention4;

*find the minimum date - ignores missing;
min_date = min(of _dates(*));

*what about ties - find index of lowest date;
index_min_date = whichn(min_date, of _dates(*));

*get relevant intervention based on index;
first_intervention = _ints(index_min_date);

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here's a tutorial on using Arrays in SAS&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-arrays/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-arrays/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/372933"&gt;@cschmidt&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I would like to identify the first occurrence of an intervention for 4 different interventions. In other words, of the 4 interventions which one occurred first. I have included sample variables and code. thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;sample data set:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;patient1&amp;nbsp; &amp;nbsp;intervention1 &amp;nbsp;int1_date &amp;nbsp;intervention2&amp;nbsp; int2_date &amp;nbsp;intervention3&amp;nbsp; int3_date &amp;nbsp;intervention4 &amp;nbsp;int4_date&lt;/P&gt;
&lt;P&gt;patient2&amp;nbsp; ............&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test2;&lt;/P&gt;
&lt;P&gt;set test;&lt;/P&gt;
&lt;P&gt;by ID;&lt;/P&gt;
&lt;P&gt;if (int1_date &amp;lt; int2_date and int1_date &amp;lt; int3_date and int1_date &amp;lt; int4_date) then int =1;&lt;/P&gt;
&lt;P&gt;if (int2_date &amp;lt; int1_date and int2_date &amp;lt; int3_date and int2_date &amp;lt; int4_date) then int =2;&lt;/P&gt;
&lt;P&gt;if (int3_date &amp;lt; int1_date and int3_date &amp;lt;int2_date and int3_date &amp;lt; int4_date) then int =3;&lt;/P&gt;
&lt;P&gt;if (int4_date&amp;lt; int1_date and int4_date &amp;lt;int2_date and int4_date &amp;lt; int3_date) then int =5;&lt;/P&gt;
&lt;P&gt;else int = 5;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 20:33:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-variable-associated-with-the-first-date-for-a/m-p/724640#M224982</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-08T20:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the variable associated with the first.date for a series of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-variable-associated-with-the-first-date-for-a/m-p/724678#M224999</link>
      <description>&lt;P&gt;One could use your approach but much more simply:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
  set test;
  if int_date1=min(of int_date:) then int=1; else
  if int_date2=min(of int_date:) then int=2; else
  if int_date3=min(of int_date:) then int=3; else
  if int_date4=min(of int_date:) then int=4;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or more generally:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
  set test;
  int=whichn(min(of int_datet:),of min_date:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The latter assumes your variables are named, int_date1, int_date2, ... int_date4, in that order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The nice thing about the latter is that it accommodates any number of consecutively named INT_DATE variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One issue, for both techniques.&amp;nbsp; If there is a tie for minimum(earliest) date, then this always chooses the leftmost.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 22:17:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-variable-associated-with-the-first-date-for-a/m-p/724678#M224999</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-08T22:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the variable associated with the first.date for a series of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-variable-associated-with-the-first-date-for-a/m-p/725189#M225215</link>
      <description>Thank you</description>
      <pubDate>Wed, 10 Mar 2021 16:25:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-variable-associated-with-the-first-date-for-a/m-p/725189#M225215</guid>
      <dc:creator>cschmidt</dc:creator>
      <dc:date>2021-03-10T16:25:33Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the variable associated with the first.date for a series of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-the-variable-associated-with-the-first-date-for-a/m-p/725190#M225216</link>
      <description>Thank you!</description>
      <pubDate>Wed, 10 Mar 2021 16:26:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-the-variable-associated-with-the-first-date-for-a/m-p/725190#M225216</guid>
      <dc:creator>cschmidt</dc:creator>
      <dc:date>2021-03-10T16:26:24Z</dc:date>
    </item>
  </channel>
</rss>

