<?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: Creating new rows based on dates in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492368#M15312</link>
    <description>&lt;P&gt;This has a whiff of an X-Y problem about it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you explain the data more and tell us what are trying to do?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://xyproblem.info/" target="_blank"&gt;http://xyproblem.info/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Sep 2018 16:41:32 GMT</pubDate>
    <dc:creator>HB</dc:creator>
    <dc:date>2018-09-04T16:41:32Z</dc:date>
    <item>
      <title>Creating new rows based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492365#M15311</link>
      <description>&lt;P&gt;I have a dataset that looks like all_dates dataset below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all_dates;
input id: $1. 
      start_dt: mmddyy10. 
      drugA_dt: mmddyy10. 
      drugB_dt: mmddyy10. 
      drugC_dt: mmddyy10. 
      drugD_dt: mmddyy10. 
      drugE_dt: mmddyy10. 
      stop_dt: mmddyy10.;
format start_dt drugA_dt drugB_dt drugC_dt  drugD_dt drugE_dt stop_dt mmddyy10.;
datalines;
A 01/01/2017 01/25/2017 02/18/2017 03/28/2017 05/10/2017 07/05/2017 12/31/2017
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to create multiple rows for the individuals based on the minimum of all dates except for start_dt. In the given example, the start_dt of second row should be the lowest of all other dates and stop_dt should be the second lowest. My final dataset should look something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input id: $1. 
      start_dt: mmddyy10. 
      drugA_dt: mmddyy10. 
      drugB_dt: mmddyy10. 
      drugC_dt: mmddyy10. 
      drugD_dt: mmddyy10. 
      drugE_dt: mmddyy10. 
      stop_dt: mmddyy10.;
format start_dt drugA_dt drugB_dt drugC_dt  drugD_dt drugE_dt stop_dt mmddyy10.;
datalines;
A 01/01/2017 01/25/2017 02/18/2017 03/28/2017 05/10/2017 07/05/2017 01/25/2017
A 01/25/2017 01/25/2017 02/18/2017 03/28/2017 05/10/2017 07/05/2017 02/18/2017
A 02/18/2017 01/25/2017 02/18/2017 03/28/2017 05/10/2017 07/05/2017 03/28/2017
A 03/28/2017 01/25/2017 02/18/2017 03/28/2017 05/10/2017 07/05/2017 05/10/2017
A 05/10/2017 01/25/2017 02/18/2017 03/28/2017 05/10/2017 07/05/2017 07/05/2017
A 07/05/2017 01/25/2017 02/18/2017 03/28/2017 05/10/2017 07/05/2017 12/31/2017
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Notice how the start_dt and stop_dt move. I have been struggling with this and cannot figure out the solution. Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 16:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492365#M15311</guid>
      <dc:creator>Mahip</dc:creator>
      <dc:date>2018-09-04T16:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new rows based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492368#M15312</link>
      <description>&lt;P&gt;This has a whiff of an X-Y problem about it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you explain the data more and tell us what are trying to do?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://xyproblem.info/" target="_blank"&gt;http://xyproblem.info/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 16:41:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492368#M15312</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2018-09-04T16:41:32Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new rows based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492372#M15313</link>
      <description>&lt;P&gt;This works for the example data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
   set all_dates (rename=(stop_dt= ostop));
   array d start_dt drugA_dt drugB_dt drugC_dt  drugD_dt drugE_dt;
   format stop_dt mmddyy10.;
   do i= 1 to dim(d);
      if i &amp;lt; dim(d) then stop_dt=d[i+1];
      else stop_dt=ostop;
      if i &amp;gt; 1 then start_dt=d[i];
      output;
   end;
   drop i ostop;
run;
      &lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Sep 2018 16:51:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492372#M15313</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-09-04T16:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new rows based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492408#M15324</link>
      <description>&lt;P&gt;I am trying to perform time-varying analysis. For this, I need data in long format, with each row corresponding to a continuous time sequence where none of the variables (here, drugs) change values. Those drug dates indicate&amp;nbsp;initiation of those drugs, which would warrant a new row. The start and stop dates indicate study duration.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 18:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492408#M15324</guid>
      <dc:creator>Mahip</dc:creator>
      <dc:date>2018-09-04T18:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new rows based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492422#M15326</link>
      <description>&lt;P&gt;This works, but only when the dates are arranged in the order I have posted. Order could very well be different: if drug A and drug B could swap positions, this doesn't work. I am trying to modify it by using something like min ( of d[i+1] - dim(d)), but it is not working. Also, when there are many individuals, I cannot arrange data in that order (because some of them use drugC first followed by drugA, unlike that of individual A posted above).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 18:37:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492422#M15326</guid>
      <dc:creator>Mahip</dc:creator>
      <dc:date>2018-09-04T18:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new rows based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492441#M15328</link>
      <description>&lt;P&gt;So, as I suggested, maybe you could explain a little and tell us what you really want to do?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 19:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492441#M15328</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2018-09-04T19:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new rows based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492442#M15329</link>
      <description>I have explained above, in reply to your previous response. I am copying the same response here:&lt;BR /&gt;&lt;BR /&gt;"I am trying to perform time-varying analysis. For this, I need data in long format, with each row corresponding to a continuous time sequence where none of the variables (here, drugs) change values. Those drug dates indicate initiation of those drugs, which would warrant a new row. The start and stop dates indicate study duration."</description>
      <pubDate>Tue, 04 Sep 2018 19:22:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492442#M15329</guid>
      <dc:creator>Mahip</dc:creator>
      <dc:date>2018-09-04T19:22:26Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new rows based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492453#M15330</link>
      <description>&lt;P&gt;That explanation really isn't helpful in understanding, at least to me.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't even know what "I need data in long format" means.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 19:35:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492453#M15330</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2018-09-04T19:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new rows based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492468#M15331</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122361"&gt;@Mahip&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This works, but only when the dates are arranged in the order I have posted. Order could very well be different: if drug A and drug B could swap positions, this doesn't work. I am trying to modify it by using something like min ( of d[i+1] - dim(d)), but it is not working. Also, when there are many individuals, I cannot arrange data in that order (because some of them use drugC first followed by drugA, unlike that of individual A posted above).&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;NONE of these dependencies are mentioned in your original post.&lt;/P&gt;
&lt;P&gt;So go back and provide examples of each of the generic types of use cases that you have and what the output order should actually be.&lt;/P&gt;
&lt;P&gt;Or spend some time writing out the rules and exceptions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There was&amp;nbsp; reason that I specifically said : This works for the example. I suspected there was something else going on that you hadn't stated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may be that your start data needs to be reformatted to indicate something like&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp;&amp;nbsp; Date Condition&lt;/P&gt;
&lt;P&gt;where condition takes on values of Start (what ever that meant) the drug name or code, and End (whatever that actually means). That would at least maintain the date order information. Especially if there are other bits of information associated with the time such as a test result or other factors involved that were related to why a drug was chosen/ changed or added.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I could not see an obvious way of using that "want" data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might also provide some idea of the following analysis steps, such a Procs or what not.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 20:13:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492468#M15331</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-09-04T20:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new rows based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492493#M15332</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;It may be that your start data needs to be reformatted to indicate something like&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp;&amp;nbsp; Date Condition&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A data structure like&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Studies&lt;/P&gt;
&lt;P&gt;Study name- A, B, C&lt;/P&gt;
&lt;P&gt;Study start date- date&lt;/P&gt;
&lt;P&gt;Study end date - date&lt;/P&gt;
&lt;P&gt;Study purpose&lt;/P&gt;
&lt;P&gt;whatever&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Drugs Administered&lt;/P&gt;
&lt;P&gt;Study name- A, B, C&lt;/P&gt;
&lt;P&gt;Drug name/id- Azol, Bzol, Cnol, Derin&lt;/P&gt;
&lt;P&gt;Drug start date-&amp;nbsp; date&lt;/P&gt;
&lt;P&gt;Drug stop date - date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Patients&lt;/P&gt;
&lt;P&gt;Patient ID- id&lt;/P&gt;
&lt;P&gt;Study name&lt;/P&gt;
&lt;P&gt;Patient diagnosis&lt;/P&gt;
&lt;P&gt;etc&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;starts to look like something with which one could do some analytic work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 21:53:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/492493#M15332</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2018-09-04T21:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new rows based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/493142#M15355</link>
      <description>&lt;P&gt;Thank you all for your comments. In short, the link below is similar to what I am trying to do, except for I have multiple time-varying variables which is throwing me off.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings12/168-2012.pdf" target="_self"&gt;http://support.sas.com/resources/papers/proceedings12/168-2012.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 18:06:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/493142#M15355</guid>
      <dc:creator>Mahip</dc:creator>
      <dc:date>2018-09-06T18:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new rows based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/494539#M15406</link>
      <description>&lt;P&gt;You don't seem to be able to explain your data nor present what it should look like.&amp;nbsp; What multiple time-varying variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Sep 2018 16:37:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-new-rows-based-on-dates/m-p/494539#M15406</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2018-09-11T16:37:30Z</dc:date>
    </item>
  </channel>
</rss>

