<?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: create dataset with 3 periods in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-dataset-with-3-periods/m-p/702688#M215235</link>
    <description>&lt;P&gt;And if there is a gap between periods, you want the gap to belong to the later period.&amp;nbsp; Is that also correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No, I ma afraid, this is not correct, I would like to consider gaps between periods, for example , like this example for one ID:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;treatment 3: should start the 7jun, and your code start the 29May.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;08MAR2018&amp;nbsp;1&lt;BR /&gt;23MAR2018&amp;nbsp;1&lt;BR /&gt;26APR2018&amp;nbsp;1&lt;BR /&gt;10MAY2018&amp;nbsp;1&lt;BR /&gt;24MAY2018&amp;nbsp;1&lt;BR /&gt;24MAY2018&amp;nbsp;2&lt;BR /&gt;26MAY2018&amp;nbsp;2&lt;BR /&gt;27MAY2018&amp;nbsp;2&lt;BR /&gt;28MAY2018&amp;nbsp;2&lt;BR /&gt;29MAY2018&amp;nbsp;2&lt;BR /&gt;07JUN2018&amp;nbsp;3&lt;BR /&gt;21JUN2018&amp;nbsp;3&lt;BR /&gt;21JUN2018&amp;nbsp;4&lt;BR /&gt;22JUN2018&amp;nbsp;4&lt;BR /&gt;23JUN2018&amp;nbsp;4&lt;BR /&gt;24JUN2018&amp;nbsp;4&lt;BR /&gt;25JUN2018&amp;nbsp;4&lt;BR /&gt;05JUL2018&amp;nbsp;5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Dec 2020 01:51:56 GMT</pubDate>
    <dc:creator>cuan</dc:creator>
    <dc:date>2020-12-01T01:51:56Z</dc:date>
    <item>
      <title>create dataset with 3 periods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dataset-with-3-periods/m-p/702676#M215226</link>
      <description>&lt;P&gt;Dear SAS community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a problem, it will be great if you can give me the solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to setup 3 periods:&lt;/P&gt;&lt;P&gt;dataset I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id&amp;nbsp;date treat&lt;/P&gt;&lt;P&gt;1 10aug2019 1&lt;/P&gt;&lt;P&gt;1 16aug2019 1&lt;/P&gt;&lt;P&gt;1 20aug2019 1&lt;/P&gt;&lt;P&gt;1 30aug2019 1&lt;/P&gt;&lt;P&gt;1 30aug2019 2&lt;/P&gt;&lt;P&gt;1 02sep2019 2&lt;/P&gt;&lt;P&gt;1 06sep2019 2&lt;/P&gt;&lt;P&gt;1 09sep2019 2&lt;/P&gt;&lt;P&gt;1 15 sep2019 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need three periods:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset I want:&lt;/P&gt;&lt;P&gt;id period&amp;nbsp;&amp;nbsp;startdt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stopdt&lt;/P&gt;&lt;P&gt;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;10 aug2019 29aug2019&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30aug2019&amp;nbsp;&amp;nbsp;09sep2019&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10sep2019&amp;nbsp; 15sep2019&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you help me wo create these a dataset with 3 startdt and 3 stopdt?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cuan.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 00:18:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dataset-with-3-periods/m-p/702676#M215226</guid>
      <dc:creator>cuan</dc:creator>
      <dc:date>2020-12-01T00:18:24Z</dc:date>
    </item>
    <item>
      <title>Re: create dataset with 3 periods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dataset-with-3-periods/m-p/702679#M215228</link>
      <description>&lt;P&gt;I presume period corresponds to treatment, except:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;If two periods have an overlapping day, you want the overlapping date to belong exclusively to the later period, correct?&lt;/LI&gt;
&lt;LI&gt;And if there is a gap between periods, you want the gap to belong to the later period.&amp;nbsp; Is that also correct?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;If so, then:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id date :date9. treat;
  format date date9.;
datalines;
1 10aug2019 1
1 16aug2019 1
1 20aug2019 1
1 30aug2019 1
1 30aug2019 2
1 02sep2019 2
1 06sep2019 2
1 09sep2019 2
1 15sep2019 3
run;

data want (keep=id treat start_dt end_dt);
  set have (keep=id treat) end=end_of_have;
  by id treat;

  merge have have (firstobs=2 keep=date rename=(date=_nxt_date));

  retain start_dt end_dt;
  format start_dt end_dt date9.;

  if first.treat then start_dt=ifn(first.id,date,sum(end_dt,1));
  if end_of_have then end_dt=date;
  else end_dt=min(date,_nxt_date-1);

  if last.treat;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRIKE&gt;Note this only works if the overlap is never more than 1 day.&lt;/STRIKE&gt;&amp;nbsp; &amp;nbsp;Reviewed the program - it DOES work if the overlap is more than 1 day.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 01:12:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dataset-with-3-periods/m-p/702679#M215228</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-12-01T01:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: create dataset with 3 periods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dataset-with-3-periods/m-p/702683#M215230</link>
      <description>&lt;P&gt;Hi ,&amp;nbsp; many thanks for this,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but look like your code doesn't work with this dataset:&lt;/P&gt;&lt;P&gt;01AUG2017&amp;nbsp;1&lt;BR /&gt;16AUG2017&amp;nbsp;1&lt;BR /&gt;30AUG2017&amp;nbsp;1&lt;BR /&gt;30AUG2017&amp;nbsp;2&lt;BR /&gt;31AUG2017&amp;nbsp;2&lt;BR /&gt;01SEP2017&amp;nbsp;2&lt;BR /&gt;02SEP2017&amp;nbsp;2&lt;BR /&gt;03SEP2017&amp;nbsp;2&lt;BR /&gt;14SEP2017&amp;nbsp;3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is getting the 3rd period: statdt=04sep2017 (correct, but stopdate=28nov2016 (incorrect),&lt;/P&gt;&lt;P&gt;it should be 14sep2017.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not surre why you are getting 28nov2016.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many tanks.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 01:15:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dataset-with-3-periods/m-p/702683#M215230</guid>
      <dc:creator>cuan</dc:creator>
      <dc:date>2020-12-01T01:15:22Z</dc:date>
    </item>
    <item>
      <title>Re: create dataset with 3 periods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dataset-with-3-periods/m-p/702686#M215233</link>
      <description>&lt;P&gt;ohh I see,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;your code is working fine, what about tif we put two id?&lt;/P&gt;&lt;P&gt;id date treat&lt;/P&gt;&lt;P&gt;1 01AUG2017&amp;nbsp;1&lt;BR /&gt;1 16AUG2017&amp;nbsp;1&lt;BR /&gt;1 30AUG2017&amp;nbsp;1&lt;BR /&gt;1 30AUG2017&amp;nbsp;2&lt;BR /&gt;1 31AUG2017&amp;nbsp;2&lt;BR /&gt;1&amp;nbsp;01SEP2017&amp;nbsp;2&lt;BR /&gt;1 02SEP2017&amp;nbsp;2&lt;BR /&gt;1 03SEP2017&amp;nbsp;2&lt;BR /&gt;1 14SEP2017&amp;nbsp;3&lt;BR /&gt;2 29NOV2016&amp;nbsp;1&lt;BR /&gt;2 13DEC2016&amp;nbsp;1&lt;BR /&gt;2 27DEC2016&amp;nbsp;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please could &amp;nbsp;you&amp;nbsp; your code with now 2 id? because if you run your actual code, with these two&amp;nbsp;id&amp;nbsp;is what stopdate (3 period) come from = 29NOV2016, and should be 14sep2017.&lt;/P&gt;&lt;P&gt;Many thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 01:26:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dataset-with-3-periods/m-p/702686#M215233</guid>
      <dc:creator>cuan</dc:creator>
      <dc:date>2020-12-01T01:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: create dataset with 3 periods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dataset-with-3-periods/m-p/702688#M215235</link>
      <description>&lt;P&gt;And if there is a gap between periods, you want the gap to belong to the later period.&amp;nbsp; Is that also correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No, I ma afraid, this is not correct, I would like to consider gaps between periods, for example , like this example for one ID:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;treatment 3: should start the 7jun, and your code start the 29May.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;08MAR2018&amp;nbsp;1&lt;BR /&gt;23MAR2018&amp;nbsp;1&lt;BR /&gt;26APR2018&amp;nbsp;1&lt;BR /&gt;10MAY2018&amp;nbsp;1&lt;BR /&gt;24MAY2018&amp;nbsp;1&lt;BR /&gt;24MAY2018&amp;nbsp;2&lt;BR /&gt;26MAY2018&amp;nbsp;2&lt;BR /&gt;27MAY2018&amp;nbsp;2&lt;BR /&gt;28MAY2018&amp;nbsp;2&lt;BR /&gt;29MAY2018&amp;nbsp;2&lt;BR /&gt;07JUN2018&amp;nbsp;3&lt;BR /&gt;21JUN2018&amp;nbsp;3&lt;BR /&gt;21JUN2018&amp;nbsp;4&lt;BR /&gt;22JUN2018&amp;nbsp;4&lt;BR /&gt;23JUN2018&amp;nbsp;4&lt;BR /&gt;24JUN2018&amp;nbsp;4&lt;BR /&gt;25JUN2018&amp;nbsp;4&lt;BR /&gt;05JUL2018&amp;nbsp;5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 01:51:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dataset-with-3-periods/m-p/702688#M215235</guid>
      <dc:creator>cuan</dc:creator>
      <dc:date>2020-12-01T01:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: create dataset with 3 periods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dataset-with-3-periods/m-p/702697#M215236</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/359116"&gt;@cuan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;And if there is a gap between periods, you want the gap to belong to the later period.&amp;nbsp; Is that also correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No, I ma afraid, this is not correct, I would like to consider gaps between periods, for example , like this example for one ID:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The last two observations of your initial problem statement had:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1 09sep2019 2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1 15 sep2019 3&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;which has 5 unaccounted-for days (10sep-14sep) between treatments 2 and 3 - i.e. a gap.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yet you stated that you expected these dates for treatments 2 and 3:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;id period&amp;nbsp;&amp;nbsp;startdt&amp;nbsp; &amp;nbsp; stopdt&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp; &amp;nbsp; 30aug2019&amp;nbsp;&amp;nbsp;09sep2019&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp;10sep2019&amp;nbsp; 15sep2019&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is clearly an example of assigning the gap to the later treatment.&amp;nbsp; Now you've introduced some mission creep.&amp;nbsp; Please take a long look at what you want and confirm before we attempt any more suggestions.&amp;nbsp; &amp;nbsp;Help us help you - state the task clearly and precisely.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 02:00:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dataset-with-3-periods/m-p/702697#M215236</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-12-01T02:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: create dataset with 3 periods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-dataset-with-3-periods/m-p/702702#M215238</link>
      <description>&lt;P&gt;&lt;STRONG&gt;my apologize for the confusion.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Will be great if you can solve my problem:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;08MAR2018&amp;nbsp;1&lt;BR /&gt;23MAR2018&amp;nbsp;1&lt;BR /&gt;26APR2018&amp;nbsp;1&lt;BR /&gt;10MAY2018&amp;nbsp;1&lt;BR /&gt;24MAY2018&amp;nbsp;1&lt;BR /&gt;24MAY2018&amp;nbsp;2&lt;BR /&gt;26MAY2018&amp;nbsp;2&lt;BR /&gt;27MAY2018&amp;nbsp;2&lt;BR /&gt;28MAY2018&amp;nbsp;2&lt;BR /&gt;29MAY2018&amp;nbsp;2&lt;BR /&gt;07JUN2018&amp;nbsp;3&lt;BR /&gt;21JUN2018&amp;nbsp;3&lt;BR /&gt;21JUN2018&amp;nbsp;4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;start date stop date&lt;/P&gt;&lt;P&gt;08mar2018&amp;nbsp; 23may2018&lt;/P&gt;&lt;P&gt;24may2018 29may2018&lt;/P&gt;&lt;P&gt;07jun2018 20jun2018&lt;/P&gt;&lt;P&gt;21jun2018 21jun2018&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cuan.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 02:11:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-dataset-with-3-periods/m-p/702702#M215238</guid>
      <dc:creator>cuan</dc:creator>
      <dc:date>2020-12-01T02:11:31Z</dc:date>
    </item>
  </channel>
</rss>

