<?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: assigning a random index-date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427401#M105386</link>
    <description>&lt;P&gt;Thank you for the prompt reply!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 13 Jan 2018 00:06:32 GMT</pubDate>
    <dc:creator>lillymaginta</dc:creator>
    <dc:date>2018-01-13T00:06:32Z</dc:date>
    <item>
      <title>assigning a random index-date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427238#M105347</link>
      <description>&lt;P&gt;I have the following dataset&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;group ptid dx_dt index_dt
0 1  1/1/2005 .
0  2 2/2/2005 .
0  3 1/2/2007 .
0 4  3/3/2006 .
1 5 1/24/2005  2/24/2005
1 6 1/6/2005   1/15/2005
1 7 4/2/2007   4/29/2007
1 8 3/3/2006   3/9/2006&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have the following data with patient in the group "0" without index_date but only diagnosis date and those in group "1" with index_Date and diagnosis date. I want to generate a random index date for group "0" based on the information obtained from group "1"&lt;/P&gt;&lt;P&gt;any help is much appreciated&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 16:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427238#M105347</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-01-12T16:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a random index-date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427242#M105348</link>
      <description>&lt;P&gt;Does this need to scale beyond your data here? Are there multiple groups and such that need to be accounted for?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this scenario it's relatively simple but if it needs to be generalized it would help to know that ahead of time.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 16:15:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427242#M105348</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-12T16:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a random index-date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427248#M105349</link>
      <description>&lt;P&gt;Hi Reeza, there are only two groups, one with index-date and the control (without index-date). I just want the randomly generated index-date for the control group to be as close as possible to group (1) taking into account that all of the randomly generated date (index-date) for the control group should occur after the diagnosis-date for that particular id.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 16:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427248#M105349</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-01-12T16:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a random index-date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427289#M105358</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;taking into account that all of the randomly generated date (index-date) for the control group should occur after the diagnosis-date for that particular id.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This wasn't included in your original criteria.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Are you looking to replicate the duration, ie time from diagnosis to index date, or replicate the dates.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 17:30:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427289#M105358</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-12T17:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a random index-date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427299#M105363</link>
      <description>&lt;P&gt;I want to the index-date of the controls to replicate the duration between the diagnosis-dt&amp;nbsp;and index-date of group "1".&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 17:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427299#M105363</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-01-12T17:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a random index-date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427303#M105364</link>
      <description>&lt;P&gt;I would assume a normal or some type of distribution then on the duration.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I would calculate the duration for the data I have, and the mean and standard deviation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then simulate a value using a Random Normal distribution and add it to the date you have.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example using Normal distribution. You'll need to check that its after the dx_dt or account for that condition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="delete_random_simulation.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17823i6A56C6F59FEA92B1/image-size/large?v=v2&amp;amp;px=999" role="button" title="delete_random_simulation.JPG" alt="delete_random_simulation.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 17:59:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427303#M105364</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-12T17:59:22Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a random index-date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427399#M105384</link>
      <description>&lt;P&gt;Thank you Reeza but the code produce duration with negative value meaning some of the index_date happen before the dx_dt, can you help correct the error&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data have;
input group patid dx_dt: mmddyy10. index_dt: mmddyy10. ;
format dx_dt index_dt mmddyy10.;
cards; 
0 1  1/1/2005 .
0  2 2/2/2005 .
0  3 1/2/2007 .
0 4  3/3/2006 .
1 5 1/24/2005  2/24/2005
1 6 1/6/2005   1/15/2005
1 7 4/2/2007   4/29/2007
1 8 3/3/2006   3/9/2006

;;;;
   run;
data have;
set have;
duration= index_dt-dx_dt;run;
   proc sql noprint;
   select mean(duration), std(duration)
   into: dur_avg, :dur_std
   from have
   where not missing(duration);
   quit;

   %put &amp;amp;dur_avg;
   %out &amp;amp;dur_std;

   data want;
   set have;
   if missing(index_dt) then
   duration= rand('normal', &amp;amp;dur_avg, &amp;amp;dur_std);
   index_dt= floor(dx_dt +duration);
   format index_dt dx_dt date9.;
   run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Jan 2018 23:54:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427399#M105384</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-01-12T23:54:00Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a random index-date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427400#M105385</link>
      <description>&lt;P&gt;I explicitly noted that issue in the comments and am leaving that up to you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could either:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. If less than 0, set to 0 and assume same day&lt;/P&gt;
&lt;P&gt;2. Use a different distribution that won't produce negative numbers&lt;/P&gt;
&lt;P&gt;3. Repeatedly generate random numbers until you get a non-negative value&lt;/P&gt;
&lt;P&gt;4. Some other options that I likely haven't thought of that makes sense given your data....&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jan 2018 00:00:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427400#M105385</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-13T00:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: assigning a random index-date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427401#M105386</link>
      <description>&lt;P&gt;Thank you for the prompt reply!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jan 2018 00:06:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/assigning-a-random-index-date/m-p/427401#M105386</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-01-13T00:06:32Z</dc:date>
    </item>
  </channel>
</rss>

