<?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: How to use &amp;quot;BY&amp;quot; or the like in PROC SQL ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-quot-BY-quot-or-the-like-in-PROC-SQL/m-p/724309#M224872</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your suggested code, yay, the line "select LOC" matters.&lt;/P&gt;
&lt;P&gt;I adjust a little bit the code to make the result totally align with my code using proc means&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table agg_amihud_vw as 
	select LOC
		,mean(agg_amh_vw) as final_amh
	  from agg_amihud_vw
	  group by LOC
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;armest regards.&lt;/P&gt;</description>
    <pubDate>Sun, 07 Mar 2021 20:55:21 GMT</pubDate>
    <dc:creator>Phil_NZ</dc:creator>
    <dc:date>2021-03-07T20:55:21Z</dc:date>
    <item>
      <title>How to use "BY" or the like in PROC SQL ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-quot-BY-quot-or-the-like-in-PROC-SQL/m-p/724257#M224844</link>
      <description>&lt;P&gt;Hi everyone!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A part of my dataset&amp;nbsp;&lt;STRONG&gt;agg_amihud_vw&lt;/STRONG&gt; &amp;nbsp;is as below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LOC	year	_TYPE_	_FREQ_	agg_amh_vw
ARG	1999	3	    13	    .
ARG	2000	3	    12	    0.0000227405
ARG	2001	3	    11	    0.0002002287
AUS	1999	3	    116	    .
AUS	2000	3	    99	    0.0000199988
AUS	2001	3	    90	    0.0000241868
AUT	1999	3	    26	    .
AUT	2000	3	    24	    0.0001970891
AUT	2001	3	    21	    0.0002672976
BEL	1999	3	    62	    .
BEL	2000	3	    53	    0.0002912877
BEL	2001	3	    50	    0.0002791486&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;what I want is to calculate means of&amp;nbsp;agg_amihud_vw through all year in each country. In particular, the desired result is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LOC	_TYPE_	_FREQ_	final_amh
ARG	1	    3	    0.0001114846
AUS	1	    3	    0.0000220928
AUT	1	    3	    0.0002321934
BEL	1	    3	    0.0002852182&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The code I am using is very simple&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=agg_amihud_vw noprint nway;
	class LOC;
	var agg_amh_vw;
	output out=final_amihud mean=final_amh;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, I am not sure if we can use PROC SQL to do the same thing? I am trying to write the code, I know the code below is wrong but is there any code similar to this one and can be applied to get my desired result above?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	select sum(agg_amh_vw)/ count(agg_amh_vw) as value format 32.12
	by LOC /* I know this line is wrong*/
	from agg_amihud_vw;
	
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Many thanks and warmest regards!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Mar 2021 08:27:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-quot-BY-quot-or-the-like-in-PROC-SQL/m-p/724257#M224844</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-07T08:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to use "BY" or the like in PROC SQL ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-quot-BY-quot-or-the-like-in-PROC-SQL/m-p/724260#M224845</link>
      <description>&lt;P&gt;Try next sql code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	select sum(agg_amh_vw)/ count(agg_amh_vw) as value format 32.12
	from agg_amihud_vw
	group by LOC;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 07 Mar 2021 08:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-quot-BY-quot-or-the-like-in-PROC-SQL/m-p/724260#M224845</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-03-07T08:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to use "BY" or the like in PROC SQL ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-quot-BY-quot-or-the-like-in-PROC-SQL/m-p/724282#M224860</link>
      <description>&lt;P&gt;You are looking for the GROUP BY feature of SQL.&amp;nbsp; Make sure to include the grouping variable(s) in the select list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also in SAS you can use the MEAN() aggregate function directly.&amp;nbsp; Other implementations of SQL might use a different name for that function, like AVERAGE().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select loc
     , mean(agg_amh_vw) as final_amh
  from agg_amihud_vw
  group by loc
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Mar 2021 14:44:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-quot-BY-quot-or-the-like-in-PROC-SQL/m-p/724282#M224860</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-07T14:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to use "BY" or the like in PROC SQL ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-quot-BY-quot-or-the-like-in-PROC-SQL/m-p/724309#M224872</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your suggested code, yay, the line "select LOC" matters.&lt;/P&gt;
&lt;P&gt;I adjust a little bit the code to make the result totally align with my code using proc means&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table agg_amihud_vw as 
	select LOC
		,mean(agg_amh_vw) as final_amh
	  from agg_amihud_vw
	  group by LOC
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;armest regards.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Mar 2021 20:55:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-quot-BY-quot-or-the-like-in-PROC-SQL/m-p/724309#M224872</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-07T20:55:21Z</dc:date>
    </item>
  </channel>
</rss>

