<?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: PROC MEANS and PROC FREQ - subgroup analyses using WHERE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-and-PROC-FREQ-subgroup-analyses-using-WHERE/m-p/787004#M251364</link>
    <description>There's an example in the documentation that shows some of the different ways summaries are generated and read into the TYPE/WAYS statements for their functionality.</description>
    <pubDate>Tue, 21 Dec 2021 19:36:23 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-12-21T19:36:23Z</dc:date>
    <item>
      <title>PROC MEANS and PROC FREQ - subgroup analyses using WHERE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-and-PROC-FREQ-subgroup-analyses-using-WHERE/m-p/786852#M251271</link>
      <description>&lt;P&gt;I'm using the sashelp.cars dataset here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) The following are 3 subgroup analyses using PROC MEANS. This isn't a lot of repetition, but for the purpose of learning, how can I best combine multiple subgroup analyses to minimize the amount of repetition in code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC MEANS DATA = sashelp.cars MAXDEC=1 N mean Median Q1 Q3 Qrange;
	Var MSRP;
		WHERE Type = 'Sports';
RUN; 

PROC MEANS DATA = sashelp.cars MAXDEC=1 N mean Median Q1 Q3 Qrange;
	Var Invoice;
		WHERE Origin = 'Europe';
RUN;

PROC MEANS DATA = sashelp.cars MAXDEC=1 N mean Median Q1 Q3 Qrange;
	Var Horsepower;
		WHERE DriveTrain = 'Rear';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If I run the following I get different results. I think what's happening is the last WHERE (DriveTrain = 'Rear') is being used for all the Vars, which is not what I want. I want it to look like the previous except all together.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC MEANS DATA = sashelp.cars MAXDEC=1 N mean Median Q1 Q3 Qrange;
	Var MSRP;
		WHERE Type = 'Sports';
	Var Invoice;
		WHERE Origin = 'Europe';
	Var Horsepower;
		WHERE DriveTrain = 'Rear';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Here are 3 subgroup analyses using PROC FREQ. Again, I would like to know how to combine multiple subgroup analyses to minimize the amount of repetition in code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC FREQ DATA = sashelp.cars;
	TABLES Type;
		WHERE Origin = 'USA';
RUN;

PROC FREQ DATA = sashelp.cars;
	TABLES Origin;
		WHERE DriveTrain = 'Front';
RUN;

PROC FREQ DATA = sashelp.cars;
	TABLES DriveTrain;
		WHERE Horsepower &amp;gt; 200;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If I run the following I get different results. Again, I think what's happening is the last WHERE (Horsepower &amp;gt; 200) is being used for all of them, which is not what I want. I want it to look like the previous except all together.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC FREQ DATA = sashelp.cars;
	TABLES Type;
		WHERE Origin = 'USA';
	TABLES Origin;
		WHERE DriveTrain = 'Front';
	TABLES DriveTrain;
		WHERE Horsepower &amp;gt; 200;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks,&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Dec 2021 22:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-and-PROC-FREQ-subgroup-analyses-using-WHERE/m-p/786852#M251271</guid>
      <dc:creator>DougHold</dc:creator>
      <dc:date>2021-12-20T22:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS and PROC FREQ - subgroup analyses using WHERE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-and-PROC-FREQ-subgroup-analyses-using-WHERE/m-p/786856#M251275</link>
      <description>&lt;P&gt;There can only be&amp;nbsp;&lt;EM&gt;one&lt;/EM&gt; active WHERE for the whole procedure. You need a separate procedure for every different subset.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Dec 2021 22:35:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-and-PROC-FREQ-subgroup-analyses-using-WHERE/m-p/786856#M251275</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-12-20T22:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS and PROC FREQ - subgroup analyses using WHERE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-and-PROC-FREQ-subgroup-analyses-using-WHERE/m-p/786860#M251277</link>
      <description>If the subgroups are split by the same variable or the variables do not overlap there are ways of doing this. But if they're entirely different variables there's not a more efficient way of doing this.&lt;BR /&gt;&lt;BR /&gt;You could do all and then just filter the results at the end with a single WHERE if you'd like instead though. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 20 Dec 2021 22:48:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-and-PROC-FREQ-subgroup-analyses-using-WHERE/m-p/786860#M251277</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-20T22:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS and PROC FREQ - subgroup analyses using WHERE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-and-PROC-FREQ-subgroup-analyses-using-WHERE/m-p/786881#M251288</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC MEANS DATA = sashelp.cars noprint;
    class drivetrain type origin;
    ways 1;
    var Horsepower msrp invoice;
    output out=stats n=&amp;nbsp;mean=&amp;nbsp;median=&amp;nbsp;q1=&amp;nbsp;q3=&amp;nbsp;qrange=/autoname;
run;
&lt;/CODE&gt;&lt;CODE class=""&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above is a one-step approach to the problem. It gives you all the statistics you want, plus others you didn't ask for, and is probably a more real-world situation where you want means for all three variables, medians for all three variables, &lt;EM&gt;etc&lt;/EM&gt;. It uses the power of PROC MEANS to pass through the data once, instead of what you originally programmed, which has to pass through the data three times; and if your example goes from needing three WHERE clauses to (for example) 20 WHERE clauses, you can see that it would be a huge amount of typing, but the method using PROC MEANS simply requires you to add more variables to the VAR statement, that's all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, there are many different forms of output from PROC MEANS, in case you want a report to include in a document, or in case you want a SAS data set (as I have shown).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I recommend you learn to use the power of PROC MEANS/PROC SUMMARY. It will help you a lot more in the long run, as I feel more real world problems are better handled this way rather than with specific WHERE statements to produce the results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 12:01:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-and-PROC-FREQ-subgroup-analyses-using-WHERE/m-p/786881#M251288</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-21T12:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS and PROC FREQ - subgroup analyses using WHERE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-and-PROC-FREQ-subgroup-analyses-using-WHERE/m-p/786884#M251290</link>
      <description>&lt;P&gt;Since the WHERE statement applies to the whole step you might need to learn how to programmatically generate the SAS code you want to run.&amp;nbsp;&amp;nbsp;That is what the macro processor is for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example you could create a macro that generates your PROC MEANS step.&amp;nbsp; Define it to take a parameter you can use to build the WHERE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mymeans(where=);
PROC MEANS   DATA = sashelp.cars MAXDEC=1 N mean Median Q1 Q3 Qrange;
  var MSRP;
  WHERE &amp;amp;where;
RUN; 
%mend mymeans;

%mymeans(where=(Type = 'Sports'));
%mymeans(where=(Origin = 'Europe'));
%mymeans(where=(DriveTrain = 'Rear'));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 03:04:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-and-PROC-FREQ-subgroup-analyses-using-WHERE/m-p/786884#M251290</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-21T03:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS and PROC FREQ - subgroup analyses using WHERE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-and-PROC-FREQ-subgroup-analyses-using-WHERE/m-p/787001#M251361</link>
      <description>&lt;P&gt;Thank you for this. I will need to be doing a lot of descriptive statistics, so i'm definitely going to have to learn more about PROC MEANS and PROC SUMMARY.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 19:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-and-PROC-FREQ-subgroup-analyses-using-WHERE/m-p/787001#M251361</guid>
      <dc:creator>DougHold</dc:creator>
      <dc:date>2021-12-21T19:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS and PROC FREQ - subgroup analyses using WHERE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-and-PROC-FREQ-subgroup-analyses-using-WHERE/m-p/787004#M251364</link>
      <description>There's an example in the documentation that shows some of the different ways summaries are generated and read into the TYPE/WAYS statements for their functionality.</description>
      <pubDate>Tue, 21 Dec 2021 19:36:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-and-PROC-FREQ-subgroup-analyses-using-WHERE/m-p/787004#M251364</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-21T19:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: PROC MEANS and PROC FREQ - subgroup analyses using WHERE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-and-PROC-FREQ-subgroup-analyses-using-WHERE/m-p/787005#M251365</link>
      <description>Thanks, this is a good idea too!</description>
      <pubDate>Tue, 21 Dec 2021 19:38:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-MEANS-and-PROC-FREQ-subgroup-analyses-using-WHERE/m-p/787005#M251365</guid>
      <dc:creator>DougHold</dc:creator>
      <dc:date>2021-12-21T19:38:07Z</dc:date>
    </item>
  </channel>
</rss>

