<?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: Displaying data range in proc sql summary in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Displaying-data-range-in-proc-sql-summary/m-p/409653#M100084</link>
    <description>&lt;P&gt;Good evening everyone!&lt;/P&gt;
&lt;P&gt;This is little modification of an earlier problem I posted on this thread. As you see in my 'Have' dataset, the months are not continuous sometimes. So, for example, if there is a&amp;nbsp;missing month&amp;nbsp;in consecutive records&amp;nbsp;(jan2014, feb2014, april 2014), I need to break down the range bit differently, so rather than original 'want' data set, my new want data set will look like-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
length date_range $35 ;
input id totalpremium date_range $ ;
cards;
1 20 01/01/2014-02/29/2014
1 10  04/01/2014 -04/30/2014
2 30 01/01/2015-02/28/2015
2 15 04/01/2015 -04/30/2015
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If there is no break per id, then the range will be from 1st day of 1st month to last day of lastmonth of that record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Wed, 01 Nov 2017 21:28:30 GMT</pubDate>
    <dc:creator>devsas</dc:creator>
    <dc:date>2017-11-01T21:28:30Z</dc:date>
    <item>
      <title>Displaying data range in proc sql summary</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-data-range-in-proc-sql-summary/m-p/407786#M99392</link>
      <description>&lt;P&gt;Good Afternoon everyone! So, I just finished summarizing a report and got everything tied together well, except displaying the date range. I have multiple records for same id's with different dates- all 1st day of the month-in the format 01/01/2014, 02/01/2014, 08/01/2017 and so on. I also have premiums etc which I need to sum for all records for the same id. What I need is to create another variable displaying the date range/span for the same id.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;


input id premium date mmddyy10. ;

format date mmddyy10. ;
cards;

1 10 01/01/2014
1 10 02/01/2014
1 10 04/01/2014
2 15 01/01/2015
2 15 02/01/2015
2 15 04/01/2015
;
run;

data want;
length date_range $35 ;
input id totalpremium date_range $ ;
cards;
1 30 01/01/2014-04/01/2014
2 45 01/01/2015-04/01/2015
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I have tried so far-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql;


create table want as select id, sum(premium) as total premium, min(date)||max(date) as date_range from have group by id;


quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2017 18:57:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-data-range-in-proc-sql-summary/m-p/407786#M99392</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2017-10-26T18:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying data range in proc sql summary</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-data-range-in-proc-sql-summary/m-p/407791#M99396</link>
      <description>&lt;P&gt;You're close! Try:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table want as
    select id, sum(premium) as total_premium,
    catx('-',put(min(date),mmddyy10.),put(max(date),mmddyy10.)) as date_range
      from have
        group by id
  ;


quit;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2017 19:07:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-data-range-in-proc-sql-summary/m-p/407791#M99396</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-10-26T19:07:49Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying data range in proc sql summary</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-data-range-in-proc-sql-summary/m-p/409653#M100084</link>
      <description>&lt;P&gt;Good evening everyone!&lt;/P&gt;
&lt;P&gt;This is little modification of an earlier problem I posted on this thread. As you see in my 'Have' dataset, the months are not continuous sometimes. So, for example, if there is a&amp;nbsp;missing month&amp;nbsp;in consecutive records&amp;nbsp;(jan2014, feb2014, april 2014), I need to break down the range bit differently, so rather than original 'want' data set, my new want data set will look like-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
length date_range $35 ;
input id totalpremium date_range $ ;
cards;
1 20 01/01/2014-02/29/2014
1 10  04/01/2014 -04/30/2014
2 30 01/01/2015-02/28/2015
2 15 04/01/2015 -04/30/2015
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If there is no break per id, then the range will be from 1st day of 1st month to last day of lastmonth of that record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 21:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-data-range-in-proc-sql-summary/m-p/409653#M100084</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2017-11-01T21:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying data range in proc sql summary</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-data-range-in-proc-sql-summary/m-p/409658#M100088</link>
      <description>&lt;P&gt;This should work but, unlike your example, there were only 28 days in Feb 2014:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  input id premium date mmddyy10. ;
  format date mmddyy10.;
  cards;
1 10 01/01/2014
1 10 02/01/2014
1 10 04/01/2014
2 15 01/01/2015
2 15 02/01/2015
2 15 04/01/2015
;

data need (drop=last_date);
  set have;
  by id;
  last_date=lag(date);
  if first.id then seq=1;
  else if intck('month',last_date,date,'D') gt 1 then seq+1;
run;

proc sql;
  create table want as
    select id, sum(premium) as total_premium,
    catx('-',put(min(date),mmddyy10.),
             put(intnx('month',max(date),0,'e'),mmddyy10.)) as date_range
      from need
        group by id,seq
  ;
quit;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 21:59:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-data-range-in-proc-sql-summary/m-p/409658#M100088</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-11-01T21:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying data range in proc sql summary</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Displaying-data-range-in-proc-sql-summary/m-p/409679#M100099</link>
      <description>&lt;P&gt;Thanks Sir so much! Really appreciate it. It worked.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 23:15:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Displaying-data-range-in-proc-sql-summary/m-p/409679#M100099</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2017-11-01T23:15:12Z</dc:date>
    </item>
  </channel>
</rss>

