<?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: Need help taking dates within a group to create new &amp;quot;start&amp;quot; and &amp;quot;end&amp;quot; dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-taking-dates-within-a-group-to-create-new-quot-start/m-p/567448#M159567</link>
    <description>&lt;P&gt;It usually helps if you post data as text rather than images. If we want to work with your data we'd have to type it out.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's a somewhat neat trick you can use to get this (untested) because I'm too lazy to type out your data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Merge BY group but set the first observation to be 2, so it gets the second row merged with the first.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me know how this works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge have (rename=date=start_date) 
           have(firstobs=2 rename=date=end_date);
by group;

if last.group then delete;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/278573"&gt;@sasburger&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm a bit stumped as to how to approach this data manipulation problem, and I'm hoping the community can help. This is my first time posting, so my apologies if I'm doing this incorrectly. I currently have a dataset that looks like this:&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="transmissiondiagramsampledata.PNG" style="width: 143px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30416i2073D5A85BECE772/image-size/large?v=v2&amp;amp;px=999" role="button" title="transmissiondiagramsampledata.PNG" alt="transmissiondiagramsampledata.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My goal is to take each date within a group and the subsequent date that follows to create two new "start" and "end" variables that indicate a date range. Here is my desired output:&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="transmissiondiagramsampledata2.PNG" style="width: 214px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30417i53E6776B33BC8D20/image-size/large?v=v2&amp;amp;px=999" role="button" title="transmissiondiagramsampledata2.PNG" alt="transmissiondiagramsampledata2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately, I do not have SAS code that I've tried, as I do not even know how to start to go about doing this. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; Any help is much appreciated.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Jun 2019 20:14:29 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-06-19T20:14:29Z</dc:date>
    <item>
      <title>Need help taking dates within a group to create new "start" and "end" dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-taking-dates-within-a-group-to-create-new-quot-start/m-p/567443#M159566</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a bit stumped as to how to approach this data manipulation problem, and I'm hoping the community can help. This is my first time posting, so my apologies if I'm doing this incorr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t;6/19/2019&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is to take each date within a group and the subsequent date that follows to create two new "start" and "end" variables that indicate a date range. Here is my desired output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;group&lt;/TD&gt;&lt;TD&gt;start&lt;/TD&gt;&lt;TD&gt;end&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;2/12/2018&lt;/TD&gt;&lt;TD&gt;7/18/2018&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;7/18/2018&lt;/TD&gt;&lt;TD&gt;8/23/2018&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;8/23/2018&lt;/TD&gt;&lt;TD&gt;10/4/2018&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;5/10/2018&lt;/TD&gt;&lt;TD&gt;9/4/2018&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;9/4/2018&lt;/TD&gt;&lt;TD&gt;12/18/2018&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;3/19/2018&lt;/TD&gt;&lt;TD&gt;6/2/2018&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;3/12/2019&lt;/TD&gt;&lt;TD&gt;4/25/2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;4/25/2019&lt;/TD&gt;&lt;TD&gt;5/23/2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;5/23/2019&lt;/TD&gt;&lt;TD&gt;6/19/2019&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, I do not have SAS code that I've tried, as I do not even know how to start to go about doing this. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; Any help is much appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 20:34:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-taking-dates-within-a-group-to-create-new-quot-start/m-p/567443#M159566</guid>
      <dc:creator>sasburger</dc:creator>
      <dc:date>2019-06-19T20:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: Need help taking dates within a group to create new "start" and "end" dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-taking-dates-within-a-group-to-create-new-quot-start/m-p/567448#M159567</link>
      <description>&lt;P&gt;It usually helps if you post data as text rather than images. If we want to work with your data we'd have to type it out.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's a somewhat neat trick you can use to get this (untested) because I'm too lazy to type out your data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Merge BY group but set the first observation to be 2, so it gets the second row merged with the first.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me know how this works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge have (rename=date=start_date) 
           have(firstobs=2 rename=date=end_date);
by group;

if last.group then delete;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/278573"&gt;@sasburger&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm a bit stumped as to how to approach this data manipulation problem, and I'm hoping the community can help. This is my first time posting, so my apologies if I'm doing this incorrectly. I currently have a dataset that looks like this:&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="transmissiondiagramsampledata.PNG" style="width: 143px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30416i2073D5A85BECE772/image-size/large?v=v2&amp;amp;px=999" role="button" title="transmissiondiagramsampledata.PNG" alt="transmissiondiagramsampledata.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My goal is to take each date within a group and the subsequent date that follows to create two new "start" and "end" variables that indicate a date range. Here is my desired output:&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="transmissiondiagramsampledata2.PNG" style="width: 214px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30417i53E6776B33BC8D20/image-size/large?v=v2&amp;amp;px=999" role="button" title="transmissiondiagramsampledata2.PNG" alt="transmissiondiagramsampledata2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately, I do not have SAS code that I've tried, as I do not even know how to start to go about doing this. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; Any help is much appreciated.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 20:14:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-taking-dates-within-a-group-to-create-new-quot-start/m-p/567448#M159567</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-19T20:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: Need help taking dates within a group to create new "start" and "end" dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-taking-dates-within-a-group-to-create-new-quot-start/m-p/567449#M159568</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by group; /* this lets you use first. and last. */
format start end mmddyy10.;
start = lag(date);
if not first.group
then do;
  end = date;
  output; /* first observation of a group will not be output */
end;
drop date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jun 2019 20:15:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-taking-dates-within-a-group-to-create-new-quot-start/m-p/567449#M159568</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-19T20:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: Need help taking dates within a group to create new "start" and "end" dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-taking-dates-within-a-group-to-create-new-quot-start/m-p/567459#M159573</link>
      <description>Thanks Reeza! I was floored by how clever this was. I will definitely post text instead of images next time.</description>
      <pubDate>Wed, 19 Jun 2019 21:13:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-taking-dates-within-a-group-to-create-new-quot-start/m-p/567459#M159573</guid>
      <dc:creator>sasburger</dc:creator>
      <dc:date>2019-06-19T21:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: Need help taking dates within a group to create new "start" and "end" dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-taking-dates-within-a-group-to-create-new-quot-start/m-p/567460#M159574</link>
      <description>Worked like a charm. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thank you so so much!</description>
      <pubDate>Wed, 19 Jun 2019 21:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-taking-dates-within-a-group-to-create-new-quot-start/m-p/567460#M159574</guid>
      <dc:creator>sasburger</dc:creator>
      <dc:date>2019-06-19T21:14:25Z</dc:date>
    </item>
  </channel>
</rss>

