<?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: Multiple group by rules int he same Proc Sql? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-group-by-rules-int-he-same-Proc-Sql/m-p/534041#M146469</link>
    <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;output out&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;results &lt;SPAN class="token function"&gt;mean&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;= n= /autoname&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 08 Feb 2019 19:41:06 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-02-08T19:41:06Z</dc:date>
    <item>
      <title>Multiple group by rules int he same Proc Sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-group-by-rules-int-he-same-Proc-Sql/m-p/534029#M146463</link>
      <description>&lt;P&gt;HI folks,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm using proc sql to summarize my data for the plot grouping by the WGT-DX and N of Month variable. This works well for the plotting data. Also, the total number of patients by (WGT_DX) variable which has 6 levels needs to be shown in each panel of the plot. I used INSERT function in the following proc sgpanel.&lt;/P&gt;
&lt;P&gt;Is there a way to use different grouping rules in the same PROC SQL? I mean,&amp;nbsp;&lt;CODE class=" language-sas"&gt;use "GROUP BY N_MONTH_ENROLLED, WGT_DX" for the "MEANS_DAYS" while using "GROUP BY&amp;nbsp;WGT_DX for the COUNT(DISPLAY_ID) to create a variable highlighted in red under N_PATIENTS int he image?&amp;nbsp;&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt; &lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CURRENT IMAGE.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26993i8AFBE7E45933D2B6/image-size/large?v=v2&amp;amp;px=999" role="button" title="CURRENT IMAGE.png" alt="CURRENT IMAGE.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SQL GROUP.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26992i4A50BE889AC79C61/image-size/large?v=v2&amp;amp;px=999" role="button" title="SQL GROUP.png" alt="SQL GROUP.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE; 
INPUT N_MONTH_ENROLLED WGT_DX MEAN_DAYS N_PATIENTS;
CARDS;
1 1 17.358 201 
1 2 29.000 1 
1 3 57.000 8 
1 4 139.200 5 
1 5 1.000 1 
1 6 49.667 6 
2 1 22.213 253 
2 2 73.500 2 
2 3 48.400 5 
2 4 88.333 3 
2 5 8.000 2 
2 6 132.000 1 
3 1 27.398 274 
3 2 0.000 2 
3 3 50.500 2 
3 4 0.000 1 
3 6 41.400 5 
4 1 26.337 273 
4 2 143.000 2 
4 3 28.667 6 
4 4 57.571 7 
4 5 0.000 1 
4 6 53.750 4 
5 1 24.623 281 
5 2 0.000 1 
5 3 45.000 4 
5 4 149.000 4 
5 5 7.000 1 
5 6 3.500 4 
6 1 22.702 309 
6 2 152.000 1 
6 3 12.000 2 
6 4 69.500 6 
6 6 72.000 1 
7 1 19.066 317 
7 2 0.000 1 
7 3 0.000 1 
7 4 12.333 3 
7 5 0.000 3 
7 6 27.400 5 
8 1 24.244 246 
8 2 8.500 4 
8 3 18.200 5 
8 4 54.500 4 
8 5 14.000 1 
8 6 16.000 2 
9 1 17.701 271 
9 2 7.000 1 
9 3 48.167 6 
9 4 65.500 8 
9 6 0.500 4 
10 1 20.129 319 
10 2 0.000 1 
10 3 56.571 7 
10 4 48.125 8 
10 5 5.500 2 
10 6 86.400 5 
11 1 14.134 329 
11 2 11.500 6 
11 3 7.400 5 
11 4 72.579 19 
11 5 0.000 3 
11 6 0.143 7 
12 1 11.216 3251 
12 2 13.246 69 
12 3 18.892 93 
12 4 65.955 156 
12 5 15.806 36 
12 6 22.512 41 
;

PROC SQL;
CREATE TABLE HAVE AS
SELECT N_MONTH_ENROLLED, WGT_DX,
MEAN(DOD_DIFF) AS MEAN_DAYS, COUNT(DISPLAY_ID) AS N_PATIENTS
FROM HAVE1
GROUP BY N_MONTH_ENROLLED,WGT_DX;
QUIT; 

ods graphics / height=400px width=800px;
TITLE "hello";
proc sgpanel data=have;
panelby wgt_dx/onepanel novarname ROWS=3;
series x=N_MONTH_ENROLLED  y=MEAN_DAYS / markerattrs=(size=3px);
INSET N_PATIENTS/position=top;
colaxis label='LABEL' fitpolicy=thin valuesformat=best2.0 values=(1 to 12 by 1);;
rowaxis label='LABEL' grid; 
TITLE "MYTITLE";
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2019 18:29:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-group-by-rules-int-he-same-Proc-Sql/m-p/534029#M146463</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2019-02-08T18:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple group by rules int he same Proc Sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-group-by-rules-int-he-same-Proc-Sql/m-p/534030#M146464</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;Is there a way to use different grouping rules in the same PROC SQL? I mean, use "GROUP BY N_MONTH_ENROLLED, WGT_DX" for the "MEANS_DAYS" while using "GROUP BY WGT_DX for the COUNT(DISPLAY_ID) to create a variable highlighted in red under N_PATIENTS int he image?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is exactly what PROC SUMMARY does.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2019 18:44:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-group-by-rules-int-he-same-Proc-Sql/m-p/534030#M146464</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-08T18:44:37Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple group by rules int he same Proc Sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-group-by-rules-int-he-same-Proc-Sql/m-p/534032#M146465</link>
      <description>proc summary with multiple class statements?</description>
      <pubDate>Fri, 08 Feb 2019 18:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-group-by-rules-int-he-same-Proc-Sql/m-p/534032#M146465</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2019-02-08T18:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple group by rules int he same Proc Sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-group-by-rules-int-he-same-Proc-Sql/m-p/534035#M146466</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132289"&gt;@Cruise&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;proc summary with multiple class statements?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;PROC SUMMARY with multiple class variables (and perhaps a TYPES or WAYS statement)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I want to take the SASHELP.CLASS and compute mean height and weight by SEX, and also by SEX * AGE, it looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=sashelp.class;
    class sex age;
    types sex sex*age;
    var height weight;
    output out=results mean=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Feb 2019 19:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-group-by-rules-int-he-same-Proc-Sql/m-p/534035#M146466</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-08T19:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple group by rules int he same Proc Sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-group-by-rules-int-he-same-Proc-Sql/m-p/534039#M146467</link>
      <description>I see ,I want mean of height by sex and age and &lt;BR /&gt;n of counts of rows by sex only. Any suggestions? &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 08 Feb 2019 19:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-group-by-rules-int-he-same-Proc-Sql/m-p/534039#M146467</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2019-02-08T19:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple group by rules int he same Proc Sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-group-by-rules-int-he-same-Proc-Sql/m-p/534041#M146469</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;output out&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;results &lt;SPAN class="token function"&gt;mean&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;= n= /autoname&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Feb 2019 19:41:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-group-by-rules-int-he-same-Proc-Sql/m-p/534041#M146469</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-08T19:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple group by rules int he same Proc Sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-group-by-rules-int-he-same-Proc-Sql/m-p/534119#M146494</link>
      <description>&lt;P&gt;Or just summarize one more level&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE HAVE AS
select 
    *, 
    sum(n_patients) as total_patients
from
    (
    SELECT  
        N_MONTH_ENROLLED, 
        WGT_DX,
        MEAN(DOD_DIFF) AS MEAN_DAYS, 
        COUNT(DISPLAY_ID) AS N_PATIENTS
    FROM HAVE1
    GROUP BY N_MONTH_ENROLLED, WGT_DX 
    )
group by wgt_dx;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;</description>
      <pubDate>Sat, 09 Feb 2019 05:37:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-group-by-rules-int-he-same-Proc-Sql/m-p/534119#M146494</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-02-09T05:37:05Z</dc:date>
    </item>
  </channel>
</rss>

