<?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: Group by in Sql with date range format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Group-by-in-Sql-with-date-range-format/m-p/571158#M161107</link>
    <description>&lt;P&gt;In your current SQL Procedure, you group by the actual dates. Not the formatted dates. You can make a small correction that makes this possible&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
     select put(date, calendar.) as date,
                sum(gbv) as gbv format commax20.
     from have
     group by calculated date
     order by date desc;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 04 Jul 2019 07:17:49 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-07-04T07:17:49Z</dc:date>
    <item>
      <title>Group by in Sql with date range format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-by-in-Sql-with-date-range-format/m-p/571156#M161106</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
     infile datalines delimiter=','; 
      attrib gbv length  = 8
               date length = 8 format = date9. informat =ddmmyy10.;
       input gbv date ;
       datalines;
       1000, 01/01/2017
        23,    10/03/2016
        344,  23/06/2014
        44,    04/11/2010
        445,  01/04/2013
        63,    21/06/2015
        7,      01/01/2018
        83,    01/09/2017
        932,  17/12/2016
       10,     05/02/2019
      ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I create this new format&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
      value calendar
                "01JAN1970"d - "31DEC2013"d = "G) ANTE 2013"
                "01JAN2014"d - "31DEC2014"d = "F) 2014"
                "01JAN2015"d - "31DEC2015"d = "E) 2015"
                "01JAN2016"d - "31DEC2016"d = "D) 2016"
                "01JAN2017"d - "31DEC2017"d = "C) 2017"
                "01JAN2018"d - "31MAR2018"d = "B) 1Q 2018"
                "01APR2018"d - "31DEC2030"d = "A) POST 2018";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And I want an output like this one that I've obtained with proc means but using sql.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 177px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30748i97FC4723E1395106/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data = have noprint nway missing;
     format date calendar.;
     class date;
     var gbv;
     output out  = want (drop = _type_ _freq_) sum=;
run;

proc sort;
     by descending date;
run;

proc print data = want;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Unluckily my proc sql dosen't work properly, I would like to have a single row for each range.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture2.PNG" style="width: 137px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30749iDF37483B90EB9BFC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture2.PNG" alt="Capture2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
     select date format calendar., 
                sum(gbv) as gbv format commax20.
     from have
     group by date
     order by date desc;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Do you know why? Could you help me to fix it?&lt;/P&gt;&lt;P&gt;Thanks a lot for your help!&lt;/P&gt;&lt;P&gt;Daniele&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 07:07:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-by-in-Sql-with-date-range-format/m-p/571156#M161106</guid>
      <dc:creator>Ccasagran737</dc:creator>
      <dc:date>2019-07-04T07:07:35Z</dc:date>
    </item>
    <item>
      <title>date range format with proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-by-in-Sql-with-date-range-format/m-p/571111#M161122</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I'm trying to create new format for summarize data in a proc sql step.&lt;/P&gt;&lt;P&gt;This is my data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;			  
data have;
  infile datalines delimiter=','; 
  attrib gbv length  = 8
         date length = 8 format = date9. informat =ddmmyy10.;
  input gbv date ;
	datalines;
	1000, 01/01/2017
	23,   10/03/2016
	344,  23/06/2014
	44,   04/11/2010
	445,  01/04/2013
	63,   21/06/2015
	7,    01/01/2018
	83,   01/09/2017
	932,  17/12/2016
	10,   05/02/2019
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I create this new format&lt;/P&gt;&lt;PRE&gt;proc format;
	value calendar
	"01JAN1970"d - "31DEC2013"d = "G) ANTE 2013"
        "01JAN2014"d - "31DEC2014"d = "F) 2014"
	"01JAN2015"d - "31DEC2015"d = "E) 2015"
	"01JAN2016"d - "31DEC2016"d = "D) 2016"
	"01JAN2017"d - "31DEC2017"d = "C) 2017"
	"01JAN2018"d - "31MAR2018"d = "B) 1Q 2018"
	"01APR2018"d - "31DEC2030"d = "A) POST 2018";
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want an output like this one that I've obtained with a proc means step but using a proc sql.&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="Cattura.PNG" style="width: 135px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30742i878233CBF15C07D5/image-size/large?v=v2&amp;amp;px=999" role="button" title="Cattura.PNG" alt="Cattura.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc means data = have noprint nway missing;
	format date calendar.;
	class date;
	var gbv;
	output out  = want (drop = _type_ _freq_) sum=;
run;
proc sort;
	by descending date;
run;

proc print data = want;
run;&lt;/PRE&gt;&lt;P&gt;Unluckily my proc sql doesn't work properly and in my output the dates are not group by in unique row&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="Cattura2.PNG" style="width: 115px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30744i1C2064AF76B551A2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Cattura2.PNG" alt="Cattura2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
	select date format calendar., 
	           sum(gbv) as gbv format commax20.
	from have
	group by date
	order by date desc;
quit;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know why and how I can fix my program?&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;Daniele&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2019 22:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-by-in-Sql-with-date-range-format/m-p/571111#M161122</guid>
      <dc:creator>Ccasagran737</dc:creator>
      <dc:date>2019-07-03T22:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: Group by in Sql with date range format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-by-in-Sql-with-date-range-format/m-p/571158#M161107</link>
      <description>&lt;P&gt;In your current SQL Procedure, you group by the actual dates. Not the formatted dates. You can make a small correction that makes this possible&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
     select put(date, calendar.) as date,
                sum(gbv) as gbv format commax20.
     from have
     group by calculated date
     order by date desc;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Jul 2019 07:17:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-by-in-Sql-with-date-range-format/m-p/571158#M161107</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-07-04T07:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Group by in Sql with date range format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-by-in-Sql-with-date-range-format/m-p/571160#M161109</link>
      <description>&lt;P&gt;Great!!! thank for your help!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 07:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-by-in-Sql-with-date-range-format/m-p/571160#M161109</guid>
      <dc:creator>Ccasagran737</dc:creator>
      <dc:date>2019-07-04T07:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: Group by in Sql with date range format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-by-in-Sql-with-date-range-format/m-p/571161#M161110</link>
      <description>&lt;P&gt;Anytime &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 07:25:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-by-in-Sql-with-date-range-format/m-p/571161#M161110</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-07-04T07:25:38Z</dc:date>
    </item>
  </channel>
</rss>

