<?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 sql group by wth date format in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/sql-group-by-wth-date-format/m-p/43014#M11202</link>
    <description>The code I'm trying to use follows.  Unfortunately, the output data is not grouped by Quarter.  How do I accomplish Quarterly grouping in the SQL setting?  I'm trying to avoid using proc summary plus a data step.&lt;BR /&gt;
&lt;BR /&gt;
Thanks!&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table weights as&lt;BR /&gt;
&lt;BR /&gt;
	select put(date,yyq6.),&lt;BR /&gt;
	       sum(slabwt) as EntryWt,&lt;BR /&gt;
				 sum(hrcoilwt) as ExitWt,&lt;BR /&gt;
	       (sum(slabwt)/sum(hrcoilwt))*1000 as Yield&lt;BR /&gt;
&lt;BR /&gt;
  from HMQandY&lt;BR /&gt;
&lt;BR /&gt;
	where EndTest='N'&lt;BR /&gt;
&lt;BR /&gt;
	group by put(date,yyq6.)&lt;BR /&gt;
;</description>
    <pubDate>Tue, 19 Jan 2010 20:58:04 GMT</pubDate>
    <dc:creator>Bill</dc:creator>
    <dc:date>2010-01-19T20:58:04Z</dc:date>
    <item>
      <title>sql group by wth date format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql-group-by-wth-date-format/m-p/43014#M11202</link>
      <description>The code I'm trying to use follows.  Unfortunately, the output data is not grouped by Quarter.  How do I accomplish Quarterly grouping in the SQL setting?  I'm trying to avoid using proc summary plus a data step.&lt;BR /&gt;
&lt;BR /&gt;
Thanks!&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table weights as&lt;BR /&gt;
&lt;BR /&gt;
	select put(date,yyq6.),&lt;BR /&gt;
	       sum(slabwt) as EntryWt,&lt;BR /&gt;
				 sum(hrcoilwt) as ExitWt,&lt;BR /&gt;
	       (sum(slabwt)/sum(hrcoilwt))*1000 as Yield&lt;BR /&gt;
&lt;BR /&gt;
  from HMQandY&lt;BR /&gt;
&lt;BR /&gt;
	where EndTest='N'&lt;BR /&gt;
&lt;BR /&gt;
	group by put(date,yyq6.)&lt;BR /&gt;
;</description>
      <pubDate>Tue, 19 Jan 2010 20:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql-group-by-wth-date-format/m-p/43014#M11202</guid>
      <dc:creator>Bill</dc:creator>
      <dc:date>2010-01-19T20:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: sql group by wth date format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql-group-by-wth-date-format/m-p/43015#M11203</link>
      <description>if you want to sum the data by quarter (as you said the data is not grouped by quarter), you have to have the variable of quarter. you may use qtr(date) to get it and add it to your grouping variables.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table weights as&lt;BR /&gt;
&lt;BR /&gt;
select put(date,yyq6.),&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;qtr(date) as quarter,&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
sum(slabwt) as EntryWt,&lt;BR /&gt;
sum(hrcoilwt) as ExitWt,&lt;BR /&gt;
(sum(slabwt)/sum(hrcoilwt))*1000 as Yield&lt;BR /&gt;
&lt;BR /&gt;
from HMQandY&lt;BR /&gt;
&lt;BR /&gt;
where EndTest='N'&lt;BR /&gt;
&lt;BR /&gt;
group by put(date,yyq6.)&lt;BR /&gt;
&lt;B&gt;  , calculated quarter&lt;/B&gt;&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
see if this works.</description>
      <pubDate>Tue, 19 Jan 2010 21:25:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql-group-by-wth-date-format/m-p/43015#M11203</guid>
      <dc:creator>abdullala</dc:creator>
      <dc:date>2010-01-19T21:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: sql group by wth date format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql-group-by-wth-date-format/m-p/43016#M11204</link>
      <description>sorry, the quarter variable should be put prior to the date variable for grouping.</description>
      <pubDate>Tue, 19 Jan 2010 21:28:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql-group-by-wth-date-format/m-p/43016#M11204</guid>
      <dc:creator>abdullala</dc:creator>
      <dc:date>2010-01-19T21:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: sql group by wth date format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql-group-by-wth-date-format/m-p/43017#M11205</link>
      <description>abdullala;&lt;BR /&gt;
&lt;BR /&gt;
Thank you for directing me to the solution.  Here's what I ended up with.&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table weights as&lt;BR /&gt;
&lt;BR /&gt;
	select put(date,yyq6.) as Qtr,&lt;BR /&gt;
	       &lt;BR /&gt;
	       sum(slabwt) as EntryWt,&lt;BR /&gt;
				 sum(hrcoilwt) as ExitWt,&lt;BR /&gt;
	       (sum(slabwt)/sum(hrcoilwt))*1000 as Yield&lt;BR /&gt;
&lt;BR /&gt;
  from HMQandY&lt;BR /&gt;
&lt;BR /&gt;
	where EndTest='N'&lt;BR /&gt;
&lt;BR /&gt;
	group by calculated Qtr&lt;BR /&gt;
;</description>
      <pubDate>Tue, 19 Jan 2010 21:47:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql-group-by-wth-date-format/m-p/43017#M11205</guid>
      <dc:creator>Bill</dc:creator>
      <dc:date>2010-01-19T21:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: sql group by wth date format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql-group-by-wth-date-format/m-p/43018#M11206</link>
      <description>The solution above results in Qtr being a character variable instead of a sas date value.  I've reworked the code so that it now groups the data in the same way while retaining the date as a sas date.  Code below.&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table HmCoilWt as&lt;BR /&gt;
&lt;BR /&gt;
	select date format=yyq6.,&lt;BR /&gt;
	       EndTest,&lt;BR /&gt;
		       sum(slabwt) as EntryWt,&lt;BR /&gt;
				 sum(hrcoilwt) as ExitWt,&lt;BR /&gt;
	       (sum(slabwt)/sum(hrcoilwt))*1000 as ProcessYld&lt;BR /&gt;
&lt;BR /&gt;
  from HMQandY&lt;BR /&gt;
&lt;BR /&gt;
	group by date,&lt;BR /&gt;
	         EndTest&lt;BR /&gt;
;</description>
      <pubDate>Wed, 20 Jan 2010 14:51:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql-group-by-wth-date-format/m-p/43018#M11206</guid>
      <dc:creator>Bill</dc:creator>
      <dc:date>2010-01-20T14:51:23Z</dc:date>
    </item>
  </channel>
</rss>

