<?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: need help with sas sql step (trying to sum by categories) in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/need-help-with-sas-sql-step-trying-to-sum-by-categories/m-p/582501#M13852</link>
    <description>&lt;UL&gt;
&lt;LI&gt;You need to include state and program in your select list to have them show up in your output data set&lt;/LI&gt;
&lt;LI&gt;For the group by syntax, that is incorrect, you need to have a comma between the variables, not AND&lt;/LI&gt;
&lt;LI&gt;You're summing projpaid_1 twice, not projpaid 1 and 2.&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table state_totals as
	select &lt;FONT size="4" color="#FF6600"&gt;&lt;STRONG&gt;state, program,&lt;/STRONG&gt; &lt;/FONT&gt;sum (projpaid_1)  as TOTAL_1, 
	sum(&lt;FONT size="4" color="#FF6600"&gt;&lt;STRONG&gt;projpaid_2&lt;/STRONG&gt;&lt;/FONT&gt;)  as TOTAL_2
	from error.state_data
	group by state&lt;STRONG&gt;&lt;FONT size="4" color="#FF6600"&gt;, &lt;/FONT&gt;&lt;/STRONG&gt;program;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281255"&gt;@marleeakerson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to create a table of sums by different categories. here is the proc means step:&lt;/P&gt;
&lt;PRE&gt;proc means data=error.state_data sum;&lt;BR /&gt;var projpaid_1 projpaid_2;&lt;BR /&gt;by program state;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;so this gives me the sums of projpaid_1 and&amp;nbsp;&amp;nbsp;projpaid_2 by state and program. I want to do the same in sas sql but cant finish the code. here is what i have:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;&lt;BR /&gt;	create table state_totals as&lt;BR /&gt;	select sum (projpaid_1)  as TOTAL_1, &lt;BR /&gt;	sum(projpaid_1)  as TOTAL_2&lt;BR /&gt;	from error.state_data&lt;BR /&gt;	group by state and program;&lt;BR /&gt;quit;&lt;/PRE&gt;
&lt;P&gt;but it just gives me the totals of all projpaid_1 and&amp;nbsp;projpaid_2, not by state and program category. How can i amend this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Aug 2019 17:43:56 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-08-20T17:43:56Z</dc:date>
    <item>
      <title>need help with sas sql step (trying to sum by categories)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/need-help-with-sas-sql-step-trying-to-sum-by-categories/m-p/582498#M13850</link>
      <description>&lt;P&gt;I am trying to create a table of sums by different categories. here is the proc means step:&lt;/P&gt;&lt;PRE&gt;proc means data=error.state_data sum;&lt;BR /&gt;var projpaid_1 projpaid_2;&lt;BR /&gt;by program state;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;so this gives me the sums of projpaid_1 and&amp;nbsp;&amp;nbsp;projpaid_2 by state and program. I want to do the same in sas sql but cant finish the code. here is what i have:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;&lt;BR /&gt;	create table state_totals as&lt;BR /&gt;	select sum (projpaid_1)  as TOTAL_1, &lt;BR /&gt;	sum(projpaid_1)  as TOTAL_2&lt;BR /&gt;	from error.state_data&lt;BR /&gt;	group by state and program;&lt;BR /&gt;quit;&lt;/PRE&gt;&lt;P&gt;but it just gives me the totals of all projpaid_1 and&amp;nbsp;projpaid_2, not by state and program category. How can i amend this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2019 17:31:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/need-help-with-sas-sql-step-trying-to-sum-by-categories/m-p/582498#M13850</guid>
      <dc:creator>marleeakerson</dc:creator>
      <dc:date>2019-08-20T17:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: need help with sas sql step (trying to sum by categories)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/need-help-with-sas-sql-step-trying-to-sum-by-categories/m-p/582501#M13852</link>
      <description>&lt;UL&gt;
&lt;LI&gt;You need to include state and program in your select list to have them show up in your output data set&lt;/LI&gt;
&lt;LI&gt;For the group by syntax, that is incorrect, you need to have a comma between the variables, not AND&lt;/LI&gt;
&lt;LI&gt;You're summing projpaid_1 twice, not projpaid 1 and 2.&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table state_totals as
	select &lt;FONT size="4" color="#FF6600"&gt;&lt;STRONG&gt;state, program,&lt;/STRONG&gt; &lt;/FONT&gt;sum (projpaid_1)  as TOTAL_1, 
	sum(&lt;FONT size="4" color="#FF6600"&gt;&lt;STRONG&gt;projpaid_2&lt;/STRONG&gt;&lt;/FONT&gt;)  as TOTAL_2
	from error.state_data
	group by state&lt;STRONG&gt;&lt;FONT size="4" color="#FF6600"&gt;, &lt;/FONT&gt;&lt;/STRONG&gt;program;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281255"&gt;@marleeakerson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to create a table of sums by different categories. here is the proc means step:&lt;/P&gt;
&lt;PRE&gt;proc means data=error.state_data sum;&lt;BR /&gt;var projpaid_1 projpaid_2;&lt;BR /&gt;by program state;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;so this gives me the sums of projpaid_1 and&amp;nbsp;&amp;nbsp;projpaid_2 by state and program. I want to do the same in sas sql but cant finish the code. here is what i have:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;&lt;BR /&gt;	create table state_totals as&lt;BR /&gt;	select sum (projpaid_1)  as TOTAL_1, &lt;BR /&gt;	sum(projpaid_1)  as TOTAL_2&lt;BR /&gt;	from error.state_data&lt;BR /&gt;	group by state and program;&lt;BR /&gt;quit;&lt;/PRE&gt;
&lt;P&gt;but it just gives me the totals of all projpaid_1 and&amp;nbsp;projpaid_2, not by state and program category. How can i amend this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2019 17:43:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/need-help-with-sas-sql-step-trying-to-sum-by-categories/m-p/582501#M13852</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-08-20T17:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: need help with sas sql step (trying to sum by categories)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/need-help-with-sas-sql-step-trying-to-sum-by-categories/m-p/582516#M13853</link>
      <description>&lt;P&gt;And if you want sums by group and state, along with state sums, along with group sums, along with overall sums, you would use PROC SUMMARY and not PROC SQL.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2019 18:08:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/need-help-with-sas-sql-step-trying-to-sum-by-categories/m-p/582516#M13853</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-20T18:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: need help with sas sql step (trying to sum by categories)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/need-help-with-sas-sql-step-trying-to-sum-by-categories/m-p/582529#M13855</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281255"&gt;@marleeakerson&lt;/a&gt;&amp;nbsp; I'm of course assuming you were aware that you can save the output from PROC MEANS directly into a data set in various forms with different levels and summaries automatically available to you. PROC SQL is not as efficient in that respect. For example in PROC MEANS you can have the overall totals and subtotals for each group included in your output as well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's some example code you can run that shows how you can capture the data from PROC MEANS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Create summary statistics for a dataset by a 'grouping' variable and store it in a dataset;

*Generate sample fake data;
data have;
	input ID          feature1         feature2         feature3;
	cards;
1               7.72               5.43              4.35
1               5.54               2.25              8.22 
1               4.43               6.75              2.22
1               3.22               3.21              7.31
2               6.72               2.86              6.11
2               5.89               4.25              5.25 
2               3.43               7.30              8.21
2               1.22               3.55              6.55

;
run;

*Create summary data;
proc means data=have noprint;
	by id;
	var feature1-feature3;
	output out=want median= var= mean= /autoname;
run;

*Show for display;
proc print data=want;
run;

*First done here:https://communities.sas.com/t5/General-SAS-Programming/Getting-creating-new-summary-variables-longitudinal-data/m-p/347940/highlight/false#M44842;
*Another way to present data is as follows;

proc means data=have stackods nway n min max mean median std p5 p95;
    by id;
    var feature1-feature3;
    ods output summary=want2;
run;

*Show for display;
proc print data=want2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Aug 2019 18:32:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/need-help-with-sas-sql-step-trying-to-sum-by-categories/m-p/582529#M13855</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-08-20T18:32:04Z</dc:date>
    </item>
  </channel>
</rss>

