<?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 proc sql -grouping in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-grouping/m-p/491100#M128706</link>
    <description>&lt;P&gt;Hello friends,&lt;/P&gt;&lt;P&gt;I want to ask if it is possible to use proc sql to calculate summary statistics per &amp;nbsp;grouping values.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;Team variable has 3 possible values: a,b,c&lt;/P&gt;&lt;P&gt;I want to group the values by using proc format : &amp;nbsp;values a and b will belong to "a,b' &amp;nbsp;and value c to &amp;nbsp;"c"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see in the code output2 is not the desired result.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl;
input ID Team $  Y;
CARDS;
1 a 2
2 b 4
3 b 6
4 c 8
5 a 10
6 a 12
7 a 14
8 c 16
9 c 18
10 c 20
;
run;
proc format;
Value $Ffmt
'a','b'='a,b'
'c'='c';
run;

PROC SQL;
	create table ouput1 as
	select 	Team ,
            count(*)  as No_Customers 
	from tbl
	group by Team
;
QUIT;


PROC SQL;
	create table ouput2 as
	select 	put(Team,$Ffmt.) as  Team_Category,
            count(*)  as No_Customers 
	from tbl
	group by put(Team,$Ffmt.)
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Aug 2018 06:08:18 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2018-08-30T06:08:18Z</dc:date>
    <item>
      <title>proc sql -grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-grouping/m-p/491100#M128706</link>
      <description>&lt;P&gt;Hello friends,&lt;/P&gt;&lt;P&gt;I want to ask if it is possible to use proc sql to calculate summary statistics per &amp;nbsp;grouping values.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;Team variable has 3 possible values: a,b,c&lt;/P&gt;&lt;P&gt;I want to group the values by using proc format : &amp;nbsp;values a and b will belong to "a,b' &amp;nbsp;and value c to &amp;nbsp;"c"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see in the code output2 is not the desired result.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl;
input ID Team $  Y;
CARDS;
1 a 2
2 b 4
3 b 6
4 c 8
5 a 10
6 a 12
7 a 14
8 c 16
9 c 18
10 c 20
;
run;
proc format;
Value $Ffmt
'a','b'='a,b'
'c'='c';
run;

PROC SQL;
	create table ouput1 as
	select 	Team ,
            count(*)  as No_Customers 
	from tbl
	group by Team
;
QUIT;


PROC SQL;
	create table ouput2 as
	select 	put(Team,$Ffmt.) as  Team_Category,
            count(*)  as No_Customers 
	from tbl
	group by put(Team,$Ffmt.)
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 06:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-grouping/m-p/491100#M128706</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-08-30T06:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql -grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-grouping/m-p/491108#M128711</link>
      <description>&lt;P&gt;Try this SQL instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	create table ouput2 as
	select 	put(Team,$Ffmt.) as  Team_Category,
            count(*)  as No_Customers 
	from tbl
	group by calculated Team_Category
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The SAS SQL compiler does not realize on its own that the expression in the group by is the same that was used for the creation of Team_Category, so you need to rub its nose in it.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 06:42:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-grouping/m-p/491108#M128711</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-30T06:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql -grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-grouping/m-p/491110#M128713</link>
      <description>&lt;P&gt;Perfect!!&lt;/P&gt;&lt;P&gt;I just want to under the logic.&lt;/P&gt;&lt;P&gt;Why &amp;nbsp;the &amp;nbsp;code: &amp;nbsp; group by put(Team,$Ffmt.) &amp;nbsp;is not working??&lt;/P&gt;&lt;P&gt;and&amp;nbsp;your code :group by calculated Team_Category &amp;nbsp; is working?&lt;/P&gt;&lt;P&gt;They should be equivalent&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 06:45:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-grouping/m-p/491110#M128713</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-08-30T06:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql -grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-grouping/m-p/491112#M128714</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Perfect!!&lt;/P&gt;
&lt;P&gt;I just want to under the logic.&lt;/P&gt;
&lt;P&gt;Why &amp;nbsp;the &amp;nbsp;code: &amp;nbsp; group by put(Team,$Ffmt.) &amp;nbsp;is not working??&lt;/P&gt;
&lt;P&gt;and&amp;nbsp;your code :group by calculated Team_Category &amp;nbsp; is working?&lt;/P&gt;
&lt;P&gt;They should be equivalent&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I already answered that. It's a shortcoming of the SAS SQL compiler. When it evaluates the group by, the expression with the put is a different object(!) than the newly created variable, although the same expression was used to create it, but that fact seems to no longer be available to the SQL compiler logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just added a new idea to the Software Ballot:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SASware-Ballot-Ideas/Enhance-the-quot-group-by-quot-evaluation-logic-of-the-SQL/idi-p/491111" target="_blank"&gt;https://communities.sas.com/t5/SASware-Ballot-Ideas/Enhance-the-quot-group-by-quot-evaluation-logic-of-the-SQL/idi-p/491111&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 06:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-grouping/m-p/491112#M128714</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-30T06:56:16Z</dc:date>
    </item>
  </channel>
</rss>

