<?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 Is there a way to combine the &amp;quot;proc freq&amp;quot; tables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-combine-the-quot-proc-freq-quot-tables/m-p/242025#M44906</link>
    <description>&lt;P&gt;Hello, all:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I kind of feel the flowing three tables generated by "proc freq" are too long. &amp;nbsp;Is there a way to make the codes shorterned? &amp;nbsp;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ying&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc freq data=A;&lt;BR /&gt;table Age * Smoke;&lt;BR /&gt;where Age in (1,2,3,4) and Smoke in (1,2,3);&lt;BR /&gt;format Age Age. SmokeStatus Smoke.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc freq data=A;&lt;BR /&gt;table gender * SMOKE;&lt;BR /&gt;where gender in (1,2) and SMOKES in (1,2,3);&lt;BR /&gt;format gender gender. SMOKE SMOKE.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc freq data=A;&lt;BR /&gt;table race * SMOKE;&lt;BR /&gt;where race in (1,2,3,4,5) and SMOKE in (1,2,3);&lt;BR /&gt;format race race. SMOKE SMOKE.;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Jan 2016 14:22:51 GMT</pubDate>
    <dc:creator>ybz12003</dc:creator>
    <dc:date>2016-01-06T14:22:51Z</dc:date>
    <item>
      <title>Is there a way to combine the "proc freq" tables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-combine-the-quot-proc-freq-quot-tables/m-p/242025#M44906</link>
      <description>&lt;P&gt;Hello, all:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I kind of feel the flowing three tables generated by "proc freq" are too long. &amp;nbsp;Is there a way to make the codes shorterned? &amp;nbsp;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ying&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc freq data=A;&lt;BR /&gt;table Age * Smoke;&lt;BR /&gt;where Age in (1,2,3,4) and Smoke in (1,2,3);&lt;BR /&gt;format Age Age. SmokeStatus Smoke.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc freq data=A;&lt;BR /&gt;table gender * SMOKE;&lt;BR /&gt;where gender in (1,2) and SMOKES in (1,2,3);&lt;BR /&gt;format gender gender. SMOKE SMOKE.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc freq data=A;&lt;BR /&gt;table race * SMOKE;&lt;BR /&gt;where race in (1,2,3,4,5) and SMOKE in (1,2,3);&lt;BR /&gt;format race race. SMOKE SMOKE.;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2016 14:22:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-combine-the-quot-proc-freq-quot-tables/m-p/242025#M44906</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2016-01-06T14:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to combine the "proc freq" tables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-combine-the-quot-proc-freq-quot-tables/m-p/242036#M44908</link>
      <description>&lt;P&gt;Is the output report too long or are you complaining about the SAS code?&lt;/P&gt;
&lt;P&gt;The problem with attempting to shorten the code is that you are filtering the data differently in each of the runs. &amp;nbsp;So the first table will allow records with out of range values for gender to still be summarized by age group. &amp;nbsp;If you wanted to create the cross tabs all in one PROC call then you would either include all values of RACE, GENDER and AGE or limit your self to the subset of records that meet all of the restrictions. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;But do you even need those WHERE clauses? &amp;nbsp;If your AGE variable is coded as 1,2,3,4 or missing then PROC FREQ table will not include the missing values anyway without the need for the WHERE clause. &amp;nbsp;Similarly do you even need to limit the values of SMOKE?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this produce the same results?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=A;
  table (Age Gender Race) * Smoke;
  format 
    Age age.
    Gender gender.
    Race race.
    Smoke smoke.
  ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If not then you might be able to use new formats to get the same effect.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  value ageX 1,2,3,4=[age.] other=' ';
  value genderX 1,2=[gender.] other=' ';
  value raceX 1,2,3,4,5=[race.] other=' ';
  value smokeX 1,2,3=[smoke.] other=' ';
run;

proc freq data=A;
  table (Age Gender Race) * Smoke;
  format 
    Age ageX.
    Gender genderX.
    Race raceX.
    Smoke smokeX.
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Jan 2016 15:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-combine-the-quot-proc-freq-quot-tables/m-p/242036#M44908</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-01-06T15:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to combine the "proc freq" tables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-combine-the-quot-proc-freq-quot-tables/m-p/242038#M44909</link>
      <description>&lt;P&gt;I dont think so. &amp;nbsp;The code is different for each proc, in the first you use smoke variable, in the other two it smokes. &amp;nbsp;The where restriction is different for each. &amp;nbsp;The format is different for each. &amp;nbsp;You could perhaps save some time by doing:&lt;/P&gt;
&lt;P&gt;data age_freq gender_freq race_freq;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; format age age. gender gender. race race. ...;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; select;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; when (age in (1,2,3,4) and smoke in (1,2,3)) output age_freq;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; when (gender in (1,2) and smokes in (1,2,3)) output gender_freq;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; ...;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; do i="age","gender","race";&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; call execute(cats('proc freq; data=',i,'_freq; tables ',i,' * smoke'; run;'))&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2016 15:04:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-combine-the-quot-proc-freq-quot-tables/m-p/242038#M44909</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-06T15:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to combine the "proc freq" tables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-combine-the-quot-proc-freq-quot-tables/m-p/242041#M44910</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;I take it that you want to obtain a more concise output. There are at least to ways to accomplish this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Use the LIST option of the TABLE(S) statement in order to obtain a one-dimensional table rather than a cross tabulation. Example:&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;table Age * Smoke / list;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Use one or more of the three options&amp;nbsp;NOROW, NOCOL or&amp;nbsp;NOPERCENT in order&amp;nbsp;to&amp;nbsp;omit row, column or overall percentages, respectively, in the cross tabulation. Example:&amp;nbsp;&lt;FONT face="courier new,courier"&gt;table Age * Smoke /&amp;nbsp;nopercent norow nocol; &lt;FONT face="arial,helvetica,sans-serif"&gt;This would restrict the output to the cell and total frequencies.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Wed, 06 Jan 2016 15:11:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-combine-the-quot-proc-freq-quot-tables/m-p/242041#M44910</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-06T15:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to combine the "proc freq" tables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-combine-the-quot-proc-freq-quot-tables/m-p/242047#M44913</link>
      <description>&lt;P&gt;Try a proc tabulate. But as mentioned above you need to ensure that the source data is the same for all of the tables.&lt;/P&gt;
&lt;P&gt;You can customize this in many different ways but hopefully it's a starting point.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc tabulate data=have;&lt;/P&gt;
&lt;P&gt;class age smoke gender race;&lt;/P&gt;
&lt;P&gt;table age gender race, smoke*n;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2016 15:21:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-combine-the-quot-proc-freq-quot-tables/m-p/242047#M44913</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-06T15:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to combine the "proc freq" tables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-combine-the-quot-proc-freq-quot-tables/m-p/242187#M44942</link>
      <description>&lt;P&gt;Thanks for all your help!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2016 14:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-combine-the-quot-proc-freq-quot-tables/m-p/242187#M44942</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2016-01-07T14:09:13Z</dc:date>
    </item>
  </channel>
</rss>

