<?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: multiple wide form dates, when does new date fit in? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/multiple-wide-form-dates-when-does-new-date-fit-in/m-p/516519#M139513</link>
    <description>&lt;P&gt;Thank you so much to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;, brilliant work, these are fabulous and solved my problem! Thank you so so much!&lt;/P&gt;</description>
    <pubDate>Tue, 27 Nov 2018 23:03:47 GMT</pubDate>
    <dc:creator>pstuchli1</dc:creator>
    <dc:date>2018-11-27T23:03:47Z</dc:date>
    <item>
      <title>multiple wide form dates, when does new date fit in?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-wide-form-dates-when-does-new-date-fit-in/m-p/515405#M139050</link>
      <description>&lt;P&gt;Apologies because this question has likely been answered, I'm just struggling to search for it in the correct way. I have n = approx 3,000 subjects with around 40 clinic visit &lt;STRONG&gt;dates&lt;/STRONG&gt; in wide format, and then two new disease diagnosis dates (two different diseases) from a newly merged dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;ID&lt;/U&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;U&gt;date1&lt;/U&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;U&gt;date2&lt;/U&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;U&gt;date3&lt;/U&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;U&gt;date40&lt;/U&gt;&amp;nbsp;&amp;nbsp; &lt;U&gt;diag_date1&lt;/U&gt;&amp;nbsp;&amp;nbsp; &lt;U&gt;diag_date2&lt;/U&gt;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I need is to find a way to determine when diag_date1 and diag_date2 fit into the clinic visit date order, or to figure out between which two clinic visit dates the diagnosis dates occurred. Another problem is that date1 to date40 may not be chronological order. One idea I had is to transpose to long form and sort, but I don't know how to write code beyond that. Or is there a better way? I have SAS 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much in advance for your help!&lt;/P&gt;</description>
      <pubDate>Thu, 22 Nov 2018 17:20:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-wide-form-dates-when-does-new-date-fit-in/m-p/515405#M139050</guid>
      <dc:creator>pstuchli1</dc:creator>
      <dc:date>2018-11-22T17:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: multiple wide form dates, when does new date fit in?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-wide-form-dates-when-does-new-date-fit-in/m-p/515411#M139053</link>
      <description>&lt;P&gt;please post sample data in the form of a datastep with datalines that represents what you have and want you want.&lt;/P&gt;
&lt;P&gt;include as many examples that show differences in the date problem you are trying to solve.&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Nov 2018 18:31:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-wide-form-dates-when-does-new-date-fit-in/m-p/515411#M139053</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-11-22T18:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: multiple wide form dates, when does new date fit in?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-wide-form-dates-when-does-new-date-fit-in/m-p/515416#M139054</link>
      <description>&lt;P&gt;You did not show how should output look.&lt;/P&gt;
&lt;P&gt;According to requirement: "...&lt;SPAN&gt;or to figure out between which two clinic visit dates the diagnosis dates occurred"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I suggest:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1) Define array of dates as: &lt;STRONG&gt;array dx{40} date1-date40;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2) Use function: &lt;STRONG&gt;call sortn(off dx(*));&amp;nbsp;&lt;/STRONG&gt;to sort the dates in the array&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3) Make a loop to locate dates:&amp;nbsp;&lt;STRONG&gt; dx(i) le diag_date le dx(i+1)&amp;nbsp;&lt;/STRONG&gt;where i le 39.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Nov 2018 19:13:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-wide-form-dates-when-does-new-date-fit-in/m-p/515416#M139054</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-11-22T19:13:07Z</dc:date>
    </item>
    <item>
      <title>Re: multiple wide form dates, when does new date fit in?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-wide-form-dates-when-does-new-date-fit-in/m-p/515450#M139071</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/146788"&gt;@pstuchli1&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create test data */

data have;
call streaminit(27182818);
length subjid 8;
array date[40];
do subjid=1 to 3000;
  do _n_=1 to dim(date);
    date[_n_]=rand('integer',11000, 21000);
  end;
  diag_date1=rand('integer',10000, 22000);
  diag_date2=rand('integer',10000, 22000);
  output;
end;
format d: yymmdd10.;
run;

/* Determine between which visit dates diagnosis dates fall:
   diag_date1 falls between dl1=date[il1] and du1=date[iu1].
   diag_date2 falls between dl2=date[il2] and du2=date[iu2].
   The lower (upper) limiting date is missing if the diagnosis date
   is smaller (greater) than the minimum (maximum) visit date.
*/

data want;
set have;
array date[40];
array diag_date[2];
array il[2];
array iu[2];
array dl[2];
array du[2];
do _k=1 to dim(diag_date);
  do _j=1 to n(of date [*]);
    _d_s=smallest(_j, of date[*]);
    _s=whichn(_d_s, of date[*]);
    if _d_s&amp;lt;=diag_date[_k] then il[_k]=_s;
    if _d_s&amp;gt;=diag_date[_k] then do;
      iu[_k]=_s;
      leave;
    end;
  end;
  if il[_k] then dl[_k]=date[il[_k]];
  if iu[_k] then du[_k]=date[iu[_k]];
end;  
format d: yymmdd10.;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Edit: Simplified the code. Checking for the extreme cases was redundant.&lt;/P&gt;
&lt;P&gt;Edit 2: Just in case that you were using an older SAS 9.4 release (or even a SAS version &amp;lt;9.4) which doesn't accept &lt;FONT face="courier new,courier"&gt;rand('integer', &lt;EM&gt;a&lt;/EM&gt;, &lt;EM&gt;b&lt;/EM&gt;)&lt;/FONT&gt;, you could replace these expressions by&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;floor((&lt;EM&gt;b&lt;/EM&gt;-&lt;EM&gt;a&lt;/EM&gt;+1)*rand('uniform')+&lt;EM&gt;a&lt;/EM&gt;)&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Nov 2018 22:37:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-wide-form-dates-when-does-new-date-fit-in/m-p/515450#M139071</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-11-22T22:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: multiple wide form dates, when does new date fit in?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-wide-form-dates-when-does-new-date-fit-in/m-p/516519#M139513</link>
      <description>&lt;P&gt;Thank you so much to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;, brilliant work, these are fabulous and solved my problem! Thank you so so much!&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 23:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-wide-form-dates-when-does-new-date-fit-in/m-p/516519#M139513</guid>
      <dc:creator>pstuchli1</dc:creator>
      <dc:date>2018-11-27T23:03:47Z</dc:date>
    </item>
  </channel>
</rss>

