<?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: Find top categories of a two-way classification table in PROC FREQ in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Find-top-categories-of-a-two-way-classification-table-in-PROC/m-p/523325#M6767</link>
    <description>&lt;P&gt;I think you want a two-way frequency containing all the cells for the 3 most populous rows (variable TYPE).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=np_codelookup order=freq  noprint;
  tables type*region /out=TR_freqs;
run;

data freqsubset;
  set tr_freqs;&lt;BR /&gt;  if type^=lag(type) then ntypes+1;
  if ntypes&amp;gt;3 then stop;
run;

ods graphics on;
proc freq data=freqsubset order=freq;
  tables Type*Region /  nocol crosslist 
         plots=freqplot(groupby=row scale=grouppercent orient=horizontal);
  weight count;
run;
ods graphics off;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apparently the "order=freq" options orders results by descending row frequency (luckily not by descending cell freq).&amp;nbsp; So data set TR_FREQS is ordered as wanted, with one observation per cell and a new variable COUNT.&amp;nbsp; Then data set freqsubset is created just to include the first 3 types.&amp;nbsp; Using this data set in the 2nd proc freq with "weight count" produces what I think you want.&lt;/P&gt;</description>
    <pubDate>Sun, 23 Dec 2018 13:31:06 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2018-12-23T13:31:06Z</dc:date>
    <item>
      <title>Find top categories of a two-way classification table in PROC FREQ</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Find-top-categories-of-a-two-way-classification-table-in-PROC/m-p/523271#M6765</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;BR /&gt;This question that is related to the SAS learning ( Programming 1 &amp;gt; Lesson 5 &amp;gt; &lt;SPAN&gt;Creating Frequency Reports &amp;gt;&amp;nbsp;Level 2 Practice: Creating Two-Way Frequency Reports&amp;nbsp;&lt;/SPAN&gt;:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;title1 'Selected Park Types by Region';
ods graphics on;
proc freq data=pg1.np_codelookup order=freq;
    tables Type*Region /  nocol crosslist 
           plots=freqplot(groupby=row scale=grouppercent orient=horizontal);
    where Type in ('National Historic Site', 'National Monument', 'National Park');
run;
title;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;How to select the&lt;/STRONG&gt; &lt;STRONG&gt;top 3 from &lt;FONT color="#FF0000"&gt;Type&lt;/FONT&gt;&lt;/STRONG&gt; instead of writing this ?&lt;/P&gt;&lt;PRE&gt;where Type in ('National Historic Site', 'National Monument', 'National Park');&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the response./ Update : Merry Xmas, Problem solved by the great community, thanks to everyone!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Dec 2018 11:56:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Find-top-categories-of-a-two-way-classification-table-in-PROC/m-p/523271#M6765</guid>
      <dc:creator>SIgnificatif</dc:creator>
      <dc:date>2018-12-26T11:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: Find top categories of a two-way classification table in PROC FREQ</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Find-top-categories-of-a-two-way-classification-table-in-PROC/m-p/523323#M6766</link>
      <description>&lt;P&gt;In a two-way table, it is not entirely clear what you mean by "top 3." Do you mean&amp;nbsp;that among all the cells, you want to print the levels of the cells that have the largest counts? If so, sort the CROSSLIST table in descending order and print or subset the first 3 observations:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=sashelp.cars order=freq noprint;
    tables Type*Origin /  nocol crosslist out=FreqOut;
run;

proc sort data=FreqOut;
by descending Count;
run;

proc print data=FreqOut(obs=3);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Dec 2018 12:05:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Find-top-categories-of-a-two-way-classification-table-in-PROC/m-p/523323#M6766</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-12-23T12:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: Find top categories of a two-way classification table in PROC FREQ</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Find-top-categories-of-a-two-way-classification-table-in-PROC/m-p/523325#M6767</link>
      <description>&lt;P&gt;I think you want a two-way frequency containing all the cells for the 3 most populous rows (variable TYPE).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=np_codelookup order=freq  noprint;
  tables type*region /out=TR_freqs;
run;

data freqsubset;
  set tr_freqs;&lt;BR /&gt;  if type^=lag(type) then ntypes+1;
  if ntypes&amp;gt;3 then stop;
run;

ods graphics on;
proc freq data=freqsubset order=freq;
  tables Type*Region /  nocol crosslist 
         plots=freqplot(groupby=row scale=grouppercent orient=horizontal);
  weight count;
run;
ods graphics off;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apparently the "order=freq" options orders results by descending row frequency (luckily not by descending cell freq).&amp;nbsp; So data set TR_FREQS is ordered as wanted, with one observation per cell and a new variable COUNT.&amp;nbsp; Then data set freqsubset is created just to include the first 3 types.&amp;nbsp; Using this data set in the 2nd proc freq with "weight count" produces what I think you want.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Dec 2018 13:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Find-top-categories-of-a-two-way-classification-table-in-PROC/m-p/523325#M6767</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-12-23T13:31:06Z</dc:date>
    </item>
  </channel>
</rss>

