<?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: Simplify the Proc Freq Coding? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-Proc-Freq-Coding/m-p/830626#M328209</link>
    <description>&lt;P&gt;ODS output will allow you to place the results of multiple tables into a single data set.&lt;/P&gt;
&lt;P&gt;You can use ( ) to group variables to create multiple tables in the tables statement: tables (a b c) * x &amp;nbsp; creates tables a*x b*x and c*x.&lt;/P&gt;
&lt;P&gt;Combine the two:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ods output crosstabfreqs=dataout1;
proc freq data=Have;
	table ( Gender age ) * RSV / chisq nopercent nocol;
	where RSV in (1,2);
	format RSV RSV. Gender Gender. ;
run;&lt;/PRE&gt;
&lt;P&gt;Place the other variables in the ( ) with gender and age.&lt;/P&gt;
&lt;P&gt;Not sure why you are filtering on RSV, so you still need to do two output sets. Note that the output data set may require some additional work to print "pretty" reports. There will be a variable that indicates which table a row of data comes from.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want a "pretty" output of counts you may want to consider a different procedure such as Proc Tabulate&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=have;
  class gender age &amp;lt;other variables go here&amp;gt;/missing;
  class rsv;
  tables gender age &amp;lt;other variables&amp;gt;,
         rsv*n
  ;
run;&lt;/PRE&gt;
&lt;P&gt;which will show the first row of variables, gender age etc as column on the left with each variable values, and column of RSV counts for each cell.&lt;/P&gt;
&lt;P&gt;The formatted values of the variables will be used to create the row/column headings if you add them to the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 26 Aug 2022 15:47:07 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-08-26T15:47:07Z</dc:date>
    <item>
      <title>Simplify the Proc Freq Coding?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-Proc-Freq-Coding/m-p/830563#M328191</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Is there a way to simplify the Proc Freq coding below?&amp;nbsp; I have extra 8 variables similar to sex and age.&amp;nbsp; If I do one single step each, I have to do 16 steps to get the results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=Have;
	table  Gender * RSV / chisq nopercent nocol  out=Dataout_sex1;
	where RSV in (1,2);
	format RSV RSV. Gender Gender. ;
run;

proc freq data=Have;
	table  Gender * RSV / chisq nopercent nocol  out=Dataout_sex2;
	where RSV in (3,4);
	format RSV RSV. Gender Gender. ;
run;

proc freq data=Have;
	table  Age * RSV / chisq nopercent nocol  out=Dataout_age1;
	where RSV in (1,2);
	format RSV RSV. Age Age. ;
run;

proc freq data=Have;
	table  Age * RSV / chisq nopercent nocol  out=Dataout_age2;
	where RSV in (3,4);
	format RSV RSV. Age Age. ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Aug 2022 12:59:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-Proc-Freq-Coding/m-p/830563#M328191</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2022-08-26T12:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify the Proc Freq Coding?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-Proc-Freq-Coding/m-p/830577#M328193</link>
      <description>&lt;P&gt;Show sample data in form of data step.&amp;nbsp; What output are you interested in freqs chisq etc.&amp;nbsp; &amp;nbsp;Show example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2022 13:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-Proc-Freq-Coding/m-p/830577#M328193</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2022-08-26T13:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify the Proc Freq Coding?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-Proc-Freq-Coding/m-p/830582#M328194</link>
      <description>&lt;P&gt;The question is - What is your definition of simple. What you have already is simple just repetative.&lt;BR /&gt;&lt;BR /&gt;Now if you want to automatically generate the repetative code you could do something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* Creae a macro with a single named parameter (multiWhere) */
/* multiWhere expects a list of where conditions seperated by a "/" */
%macro simple(multiWhere=) ;
	/* The %put statements are for debugging/seeing what happens */
	%put &amp;amp;=multiWhere ;
	/* create a counter (n) */
	%let n=1 ;
	/* scan multiWhere for the nth word using / as a seperator */
	%let where=%scan(&amp;amp;multiWhere,&amp;amp;n,"/") ;
	%put &amp;amp;=n &amp;amp;=where ;
	/* Repeat this step while &amp;amp;where has a value */
	%do %while(&amp;amp;where ne ) ;
		
		/* You code goes here */
		proc freq data=sashelp.class ;
		    /* Note the Dataout_sex&amp;amp;n the &amp;amp;n will be replaced by the value of the counter (&amp;amp;n) */
			table  sex * age / out=Dataout_sex&amp;amp;n;
			where sex in ("&amp;amp;where");
		run;

		/* Time to move onto the next Where clause */
		/* Increment the counter */
		%let n=%eval(&amp;amp;n+1) ;
		/* Get the next where clause */
		%let where=%scan(&amp;amp;multiWhere,&amp;amp;n,"/") ;
		%put &amp;amp;=n &amp;amp;=where ;
	%end ;

%mend  ;

/* Call the simple macro, passing a list of where clauses */
%simple(multiWhere=M/F) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2022 13:39:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-Proc-Freq-Coding/m-p/830582#M328194</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2022-08-26T13:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify the Proc Freq Coding?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-Proc-Freq-Coding/m-p/830602#M328195</link>
      <description>&lt;P&gt;From the example you shared it looks like you have a 3rd category: if RSV is (1,2) vs RSV is (3.,4). If you make a dummy variable with that flag, perhaps you could then use PROC FREQ for an n-way analysis.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2022 14:18:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-Proc-Freq-Coding/m-p/830602#M328195</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2022-08-26T14:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify the Proc Freq Coding?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-Proc-Freq-Coding/m-p/830626#M328209</link>
      <description>&lt;P&gt;ODS output will allow you to place the results of multiple tables into a single data set.&lt;/P&gt;
&lt;P&gt;You can use ( ) to group variables to create multiple tables in the tables statement: tables (a b c) * x &amp;nbsp; creates tables a*x b*x and c*x.&lt;/P&gt;
&lt;P&gt;Combine the two:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ods output crosstabfreqs=dataout1;
proc freq data=Have;
	table ( Gender age ) * RSV / chisq nopercent nocol;
	where RSV in (1,2);
	format RSV RSV. Gender Gender. ;
run;&lt;/PRE&gt;
&lt;P&gt;Place the other variables in the ( ) with gender and age.&lt;/P&gt;
&lt;P&gt;Not sure why you are filtering on RSV, so you still need to do two output sets. Note that the output data set may require some additional work to print "pretty" reports. There will be a variable that indicates which table a row of data comes from.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want a "pretty" output of counts you may want to consider a different procedure such as Proc Tabulate&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=have;
  class gender age &amp;lt;other variables go here&amp;gt;/missing;
  class rsv;
  tables gender age &amp;lt;other variables&amp;gt;,
         rsv*n
  ;
run;&lt;/PRE&gt;
&lt;P&gt;which will show the first row of variables, gender age etc as column on the left with each variable values, and column of RSV counts for each cell.&lt;/P&gt;
&lt;P&gt;The formatted values of the variables will be used to create the row/column headings if you add them to the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2022 15:47:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-Proc-Freq-Coding/m-p/830626#M328209</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-08-26T15:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify the Proc Freq Coding?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-Proc-Freq-Coding/m-p/830638#M328216</link>
      <description>No need to</description>
      <pubDate>Fri, 26 Aug 2022 16:51:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-Proc-Freq-Coding/m-p/830638#M328216</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2022-08-26T16:51:13Z</dc:date>
    </item>
  </channel>
</rss>

