<?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 PROC REPORT only show top frequencies in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-REPORT-only-show-top-frequencies/m-p/362883#M64581</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to generate a report of cross-tabulated frequencies. However, one of the categorical variables (language) has a ton of different options. I would like a way for the report to only show the top 4 languages and group the rest into an "other" category. How would I do this? Here's my code so far:&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;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC REPORT data= nodup_list nowd missing;
 	column motherdominantlanguage have_phone, (N pctn) Total;
	define motherdominantlanguage / group "Language" order=freq descending;
	define have_phone / across order = external "Phone Status"; 
	define n / format = 8. "N" ;
	define pctn / 'Percent' format=percent7.1 ;
	rbreak after / dol skip summarize ; 
	compute total;
 		Total = sum(_c2_,_c4_);
 	endcomp; 
	title2 "Mother's Language Frequency";
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And here's a sample of my current output:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/9146iF37FE7756762F0D4/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="language.PNG" title="language.PNG" width="397" height="660" /&gt;&lt;/P&gt;&lt;P&gt;I'd really like to only have 5 language rows: top 4 languages and an other category!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 30 May 2017 21:05:01 GMT</pubDate>
    <dc:creator>katb</dc:creator>
    <dc:date>2017-05-30T21:05:01Z</dc:date>
    <item>
      <title>PROC REPORT only show top frequencies</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-REPORT-only-show-top-frequencies/m-p/362883#M64581</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to generate a report of cross-tabulated frequencies. However, one of the categorical variables (language) has a ton of different options. I would like a way for the report to only show the top 4 languages and group the rest into an "other" category. How would I do this? Here's my code so far:&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;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC REPORT data= nodup_list nowd missing;
 	column motherdominantlanguage have_phone, (N pctn) Total;
	define motherdominantlanguage / group "Language" order=freq descending;
	define have_phone / across order = external "Phone Status"; 
	define n / format = 8. "N" ;
	define pctn / 'Percent' format=percent7.1 ;
	rbreak after / dol skip summarize ; 
	compute total;
 		Total = sum(_c2_,_c4_);
 	endcomp; 
	title2 "Mother's Language Frequency";
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And here's a sample of my current output:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/9146iF37FE7756762F0D4/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="language.PNG" title="language.PNG" width="397" height="660" /&gt;&lt;/P&gt;&lt;P&gt;I'd really like to only have 5 language rows: top 4 languages and an other category!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2017 21:05:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-REPORT-only-show-top-frequencies/m-p/362883#M64581</guid>
      <dc:creator>katb</dc:creator>
      <dc:date>2017-05-30T21:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT only show top frequencies</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-REPORT-only-show-top-frequencies/m-p/362892#M64582</link>
      <description>&lt;P&gt;Do the crosstab frequencies first (PROC FREQ), writing two intermediate data sets (NEED1 for crosstabs, and NEED2 for oneway freqs of motherdominantlanguage).&amp;nbsp; Then left join the top 4 from need2 with need1 to make NEED.&amp;nbsp; NEED will have the 8 cells of interest plus a frequency variable COUNT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq nodup_list order=freq noprint ;
  tables motherdominantlanguage*have_phone 
    / out=need1 (drop=percent) sparse missing ;
  tables motherdominantlanguage      
    / out=need2 ;
run;

proc sql;
  create table need as select n1.* from
    need2 (obs=4) as n2 
      left join 
    need1 as n1
      on n2.motherdominantlanguage=n1.motherdominantlanguage;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;AT this point you can run your proc report against dataset NEED, but add a&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; FREQ COUNT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;statement.&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2017 21:44:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-REPORT-only-show-top-frequencies/m-p/362892#M64582</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-05-30T21:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT only show top frequencies</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-REPORT-only-show-top-frequencies/m-p/362905#M64583</link>
      <description>&lt;P&gt;Have you considered a custom format?&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2017 22:24:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-REPORT-only-show-top-frequencies/m-p/362905#M64583</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-30T22:24:24Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT only show top frequencies</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-REPORT-only-show-top-frequencies/m-p/363058#M64591</link>
      <description>Thank you so much! That was definitely helpful. Is there a way to combine all the other languages into an "others" category? Thanks again!</description>
      <pubDate>Wed, 31 May 2017 13:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-REPORT-only-show-top-frequencies/m-p/363058#M64591</guid>
      <dc:creator>katb</dc:creator>
      <dc:date>2017-05-31T13:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT only show top frequencies</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-REPORT-only-show-top-frequencies/m-p/363096#M64592</link>
      <description>&lt;P&gt;Just as the "obs=4" data set name option for need2 allows joining only on the 4 most frequent languages, you can also use the "firstobs=5" data set name option to perform a join on the remaining languages.&amp;nbsp; Create a table NEED3 from this join, summing up the value of count for each have_phone value ("group by have_phone"), and creating a lable for that collection of languages ("other"=motherdominantlanguage).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can do a union of NEED3 with the join produced using "obs=4":&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  create table need3 as
    select 'Other' as motherdominantlanguage,n1.have_phone,sum(n1.count) as count from 
    need2 (firstobs=5) as n2    /* was "firstobs=2" - editted to "firstobs=5" */
      left join
    need1 as n1
      on n2.motherdominantlanguage=n1.motherdominantlanguage
    group by have_phone;

  create table need as select n1.* from
    need2 (obs=4) as n2 
      left join 
    need1 as n1
      on n2.motherdominantlanguage=n1.motherdominantlanguage
    outer union 
    select * from need3;


quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Jun 2017 15:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-REPORT-only-show-top-frequencies/m-p/363096#M64592</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-06-01T15:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT only show top frequencies</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-REPORT-only-show-top-frequencies/m-p/363131#M64593</link>
      <description>Thank you so much! It worked perfectly! I actually wound up just stacking the final two tables; made it a bit easier. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 31 May 2017 15:46:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-REPORT-only-show-top-frequencies/m-p/363131#M64593</guid>
      <dc:creator>katb</dc:creator>
      <dc:date>2017-05-31T15:46:28Z</dc:date>
    </item>
  </channel>
</rss>

