<?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 How to turn consecutive dates in one period? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-turn-consecutive-dates-in-one-period/m-p/434832#M28093</link>
    <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 438px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18367iF85FF70F45BB15F2/image-dimensions/438x224?v=v2" width="438" height="224" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Above is an extract of the data I need to work with.&lt;BR /&gt;When the same PERNR has consecutive periods with the same ZH2RCRM1 code, I want all that information in just 1 line.&lt;/P&gt;&lt;P&gt;For example PERNR 01687600 has 3 consecutive periods with the same ZH2RCRM1 code (5210).&lt;/P&gt;&lt;P&gt;What I want is to turn those 3 records into one:&lt;/P&gt;&lt;P&gt;01687600&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 13OCT2014&amp;nbsp;&amp;nbsp;&amp;nbsp; 31DEC9999&amp;nbsp;&amp;nbsp; 5210&lt;/P&gt;&lt;P&gt;I just started in SAS so I have no idea of doing this.&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Wed, 07 Feb 2018 12:52:39 GMT</pubDate>
    <dc:creator>Davoz7</dc:creator>
    <dc:date>2018-02-07T12:52:39Z</dc:date>
    <item>
      <title>How to turn consecutive dates in one period?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-turn-consecutive-dates-in-one-period/m-p/434832#M28093</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 438px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18367iF85FF70F45BB15F2/image-dimensions/438x224?v=v2" width="438" height="224" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Above is an extract of the data I need to work with.&lt;BR /&gt;When the same PERNR has consecutive periods with the same ZH2RCRM1 code, I want all that information in just 1 line.&lt;/P&gt;&lt;P&gt;For example PERNR 01687600 has 3 consecutive periods with the same ZH2RCRM1 code (5210).&lt;/P&gt;&lt;P&gt;What I want is to turn those 3 records into one:&lt;/P&gt;&lt;P&gt;01687600&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 13OCT2014&amp;nbsp;&amp;nbsp;&amp;nbsp; 31DEC9999&amp;nbsp;&amp;nbsp; 5210&lt;/P&gt;&lt;P&gt;I just started in SAS so I have no idea of doing this.&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 12:52:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-turn-consecutive-dates-in-one-period/m-p/434832#M28093</guid>
      <dc:creator>Davoz7</dc:creator>
      <dc:date>2018-02-07T12:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to turn consecutive dates in one period?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-turn-consecutive-dates-in-one-period/m-p/434851#M28095</link>
      <description>&lt;P&gt;You do have one more decision to make ... how to treat SUBTY.&amp;nbsp; In your sample data, it is constant.&amp;nbsp; But what if it were to change?&amp;nbsp; What value should be used?&amp;nbsp; Should different values signal different groupings?&amp;nbsp; At any rate, here is one approach that assumes your data is sorted as indicated in&amp;nbsp;your sample data.&amp;nbsp; It also assumes your date variables are actual SAS date values (not character strings ... a PROC CONTENTS will reveal that much):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc summary data=have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; var begda endda;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; id subty;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by pernr zzh2rcrm1 notsorted;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output out=want (drop=_type_) max(endda) = endda&amp;nbsp; min(begda) = begda;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This program also adds a variable named _FREQ_ that indicates how many observations were collapsed in order to form the resulting observation.&amp;nbsp; If&amp;nbsp;you don't want that in the output, add it to the drop list:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(drop = _type_ _freq_)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 14:03:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-turn-consecutive-dates-in-one-period/m-p/434851#M28095</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-07T14:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to turn consecutive dates in one period?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-turn-consecutive-dates-in-one-period/m-p/434866#M28100</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture1.PNG" style="width: 497px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18369i19ED3CB1E3F2669B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture1.PNG" alt="Capture1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you very much for your reply. It helped a lot!&lt;BR /&gt;For the SUBTY variable: it remains constant throughout the whole dataset&lt;BR /&gt;The date variables are indeed SAS date values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just one more thing. I noticed that I also have PERNRs who have some dates that are consecutive than a&amp;nbsp;'standalone' period and then again some consecutive dates as you can see in the picture above (PERNR 09625800)&lt;/P&gt;&lt;P&gt;For that PERNR my output should be:&lt;/P&gt;&lt;P&gt;09625800&amp;nbsp;&amp;nbsp; 0001&amp;nbsp;&amp;nbsp; 01JUN2012&amp;nbsp;&amp;nbsp; 31OCT2012&amp;nbsp; 5210&lt;BR /&gt;09625800&amp;nbsp;&amp;nbsp; 0001&amp;nbsp;&amp;nbsp; 17JUN2013&amp;nbsp;&amp;nbsp; 31OCT2013&amp;nbsp;&amp;nbsp;5210&lt;BR /&gt;09625800&amp;nbsp;&amp;nbsp; 0001&amp;nbsp;&amp;nbsp; 01JUL2014&amp;nbsp;&amp;nbsp;&amp;nbsp; 30SEP2014&amp;nbsp; 5210&lt;BR /&gt;09625800&amp;nbsp;&amp;nbsp; 0001&amp;nbsp;&amp;nbsp; 01JUL2015&amp;nbsp;&amp;nbsp;&amp;nbsp; 24JAN2016&amp;nbsp; 5210&lt;/P&gt;&lt;P&gt;instead of:&lt;/P&gt;&lt;P&gt;09625800&amp;nbsp;&amp;nbsp; 0001&amp;nbsp;&amp;nbsp; 01JUN2012&amp;nbsp;&amp;nbsp;&amp;nbsp; 24JAN2016 5210&lt;/P&gt;&lt;P&gt;In general: I can't 'lose' any dates in my output&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Sorry if it wasn't very clear&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 14:25:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-turn-consecutive-dates-in-one-period/m-p/434866#M28100</guid>
      <dc:creator>Davoz7</dc:creator>
      <dc:date>2018-02-07T14:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to turn consecutive dates in one period?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-turn-consecutive-dates-in-one-period/m-p/434871#M28101</link>
      <description>&lt;P&gt;For that situation, you will need to construct your own grouping variable before running PROC SUMMARY.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data temp;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by pernr zzh2rcrm1 notsorted;&lt;/P&gt;
&lt;P&gt;prior_end = lag(endda);&lt;/P&gt;
&lt;P&gt;if first.zzh2crm1 or begda ne prior_end + 1 then group + 1;&lt;/P&gt;
&lt;P&gt;drop prior_end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc summary data=&lt;FONT color="#ff0000"&gt;temp&lt;/FONT&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; var begda endda;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; id subty;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by pernr zzh2rcrm1 &lt;FONT color="#ff0000"&gt;group &lt;/FONT&gt;notsorted;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output out=want (drop=_type_ &lt;FONT color="#ff0000"&gt;group&lt;/FONT&gt;) max(endda) = endda&amp;nbsp; min(begda) = begda;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 14:36:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-turn-consecutive-dates-in-one-period/m-p/434871#M28101</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-07T14:36:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to turn consecutive dates in one period?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-turn-consecutive-dates-in-one-period/m-p/434877#M28102</link>
      <description>&lt;P&gt;This is exactly what I wanted!&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 14:50:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-turn-consecutive-dates-in-one-period/m-p/434877#M28102</guid>
      <dc:creator>Davoz7</dc:creator>
      <dc:date>2018-02-07T14:50:25Z</dc:date>
    </item>
  </channel>
</rss>

