<?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: Freq table with request to disaply 6 categories only (one is Other) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Freq-table-with-request-to-disaply-6-categories-only-one-is/m-p/786062#M250923</link>
    <description>Thanks, may you please  show code for your solution?</description>
    <pubDate>Tue, 14 Dec 2021 21:33:30 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2021-12-14T21:33:30Z</dc:date>
    <item>
      <title>Freq table with request to disaply 6 categories only (one is Other)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Freq-table-with-request-to-disaply-6-categories-only-one-is/m-p/786052#M250914</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I would like to do the following:&lt;/P&gt;
&lt;P&gt;Create a frequency report that count number of customers in each group.&lt;/P&gt;
&lt;P&gt;I would like to add the following condtion :&lt;/P&gt;
&lt;P&gt;1-I want that the most frequent group will be displayed first and so on (Desending order).&lt;/P&gt;
&lt;P&gt;2-I want to display only 6 groups (First 5 groups and the 6th group will get the total count for all groups that are ranked above 5th group)&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;The frequency for each group is:&lt;/P&gt;
&lt;P&gt;c 10&lt;BR /&gt;b 8&lt;BR /&gt;a 6&lt;BR /&gt;d 6&lt;BR /&gt;e 5&lt;/P&gt;
&lt;P&gt;f 3&amp;nbsp;&lt;/P&gt;
&lt;P&gt;g 2&lt;/P&gt;
&lt;P&gt;h 1&lt;/P&gt;
&lt;P&gt;i 1&lt;/P&gt;
&lt;P&gt;j 1&lt;/P&gt;
&lt;P&gt;k 1&lt;/P&gt;
&lt;P&gt;l 1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;m 2&lt;/P&gt;
&lt;P&gt;n 1&lt;/P&gt;
&lt;P&gt;o 2&lt;/P&gt;
&lt;P&gt;So wanted data set should be :&lt;/P&gt;
&lt;P&gt;c 10&lt;BR /&gt;b 8&lt;BR /&gt;a 6&lt;BR /&gt;d 6&lt;BR /&gt;e 5&lt;/P&gt;
&lt;P&gt;Other 15&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the way to do it please? (Get 6 groups)?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data have;
Input ID  group $;
cards;
1 c
2 c
3 c
4 c
5 c
6 c
7 c
8 c
9 c
10 c
11 b
12 b
13 b
14 b
15 b
16 b
17 b
18 b
19 a
20 a
21 a
22 a
23 a
24 a
25 d
26 d
27 d
28 d
29 d
30 d
31 e
32 e
33 e
34 e
35 e
36 f
37 f
38 f
39 g
40 g
41 h
42  i
43 j
44 k
45 l
46 m
47 m
48 n
49 o
50 o
;
Run;

Data wanted;
input group $ count;
cards;
c 10
b 8
a 6
d 6
e 5
Other 15
;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 21:05:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Freq-table-with-request-to-disaply-6-categories-only-one-is/m-p/786052#M250914</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-14T21:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: Freq table with request to disaply 6 categories only (one is Other)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Freq-table-with-request-to-disaply-6-categories-only-one-is/m-p/786055#M250917</link>
      <description>&lt;P&gt;I think that this solution can work well but maybe there is a better way (shorter?)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table t1 AS
select group,
       count(*) as nr
from have
group by  group
order by nr desc
;
quit;

data t2;
Serial + 1 ;
set t1;
run ;

proc sql;
create table t3 AS
select 'Other' as group,
       count(*) as nr
from t2
where Serial &amp;gt;5
;
quit;

Data wanted;
set t2(where=(Serial &amp;lt;=5)  t3 ;
Run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Dec 2021 21:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Freq-table-with-request-to-disaply-6-categories-only-one-is/m-p/786055#M250917</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-14T21:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: Freq table with request to disaply 6 categories only (one is Other)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Freq-table-with-request-to-disaply-6-categories-only-one-is/m-p/786059#M250920</link>
      <description>&lt;OL&gt;
&lt;LI&gt;Do a proc freq and get summaries into a data set&lt;/LI&gt;
&lt;LI&gt;Sort by frequency to get top 6 versus others&lt;/LI&gt;
&lt;LI&gt;Create a custom format that groups the top N into individual categories and everything else goes to other. Use PROC FORMAT + CNTLIN to do this step&lt;/LI&gt;
&lt;LI&gt;Re-run Step1 applying custom format from #3&lt;/LI&gt;
&lt;/OL&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I would like to do the following:&lt;/P&gt;
&lt;P&gt;Create a frequency report that count number of customers in each group.&lt;/P&gt;
&lt;P&gt;I would like to add the following condtion :&lt;/P&gt;
&lt;P&gt;1-I want that the most frequent group will be displayed first and so on (Desending order).&lt;/P&gt;
&lt;P&gt;2-I want to display only 6 groups (First 5 groups and the 6th group will get the total count for all groups that are ranked above 5th group)&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;The frequency for each group is:&lt;/P&gt;
&lt;P&gt;c 10&lt;BR /&gt;b 8&lt;BR /&gt;a 6&lt;BR /&gt;d 6&lt;BR /&gt;e 5&lt;/P&gt;
&lt;P&gt;f 3&amp;nbsp;&lt;/P&gt;
&lt;P&gt;g 2&lt;/P&gt;
&lt;P&gt;h 1&lt;/P&gt;
&lt;P&gt;i 1&lt;/P&gt;
&lt;P&gt;j 1&lt;/P&gt;
&lt;P&gt;k 1&lt;/P&gt;
&lt;P&gt;l 1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;m 2&lt;/P&gt;
&lt;P&gt;n 1&lt;/P&gt;
&lt;P&gt;o 2&lt;/P&gt;
&lt;P&gt;So wanted data set should be :&lt;/P&gt;
&lt;P&gt;c 10&lt;BR /&gt;b 8&lt;BR /&gt;a 6&lt;BR /&gt;d 6&lt;BR /&gt;e 5&lt;/P&gt;
&lt;P&gt;Other 15&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the way to do it please? (Get 6 groups)?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data have;
Input ID  group $;
cards;
1 c
2 c
3 c
4 c
5 c
6 c
7 c
8 c
9 c
10 c
11 b
12 b
13 b
14 b
15 b
16 b
17 b
18 b
19 a
20 a
21 a
22 a
23 a
24 a
25 d
26 d
27 d
28 d
29 d
30 d
31 e
32 e
33 e
34 e
35 e
36 f
37 f
38 f
39 g
40 g
41 h
42  i
43 j
44 k
45 l
46 m
47 m
48 n
49 o
50 o
;
Run;

Data wanted;
input group $ count;
cards;
c 10
b 8
a 6
d 6
e 5
Other 15
;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 21:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Freq-table-with-request-to-disaply-6-categories-only-one-is/m-p/786059#M250920</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-14T21:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Freq table with request to disaply 6 categories only (one is Other)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Freq-table-with-request-to-disaply-6-categories-only-one-is/m-p/786062#M250923</link>
      <description>Thanks, may you please  show code for your solution?</description>
      <pubDate>Tue, 14 Dec 2021 21:33:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Freq-table-with-request-to-disaply-6-categories-only-one-is/m-p/786062#M250923</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-14T21:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: Freq table with request to disaply 6 categories only (one is Other)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Freq-table-with-request-to-disaply-6-categories-only-one-is/m-p/786066#M250926</link>
      <description>I'm fairly certain you can figure out the code &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;If you need help post your code and issues.&lt;BR /&gt;&lt;BR /&gt;Not sure it's any more efficient than your current solution though.</description>
      <pubDate>Tue, 14 Dec 2021 21:50:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Freq-table-with-request-to-disaply-6-categories-only-one-is/m-p/786066#M250926</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-14T21:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: Freq table with request to disaply 6 categories only (one is Other)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Freq-table-with-request-to-disaply-6-categories-only-one-is/m-p/786068#M250928</link>
      <description>May you please  show step 3?</description>
      <pubDate>Tue, 14 Dec 2021 21:53:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Freq-table-with-request-to-disaply-6-categories-only-one-is/m-p/786068#M250928</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-14T21:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: Freq table with request to disaply 6 categories only (one is Other)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Freq-table-with-request-to-disaply-6-categories-only-one-is/m-p/786073#M250933</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data counts_fmt;
set counts (OBS=3) end=eof;
length label $10.;

fmtname = 'Age_fmt';
start = age;
label = put(age, 8. -l);

output;
if eof then do;
hlo = 'O';
label = 'Other';
output;
end;

run;

proc format cntlin=counts_fmt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Assuming I was doing this for an age variable and taking the top 3 instead of 6.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 22:42:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Freq-table-with-request-to-disaply-6-categories-only-one-is/m-p/786073#M250933</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-14T22:42:07Z</dc:date>
    </item>
    <item>
      <title>Re: Freq table with request to disaply 6 categories only (one is Other)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Freq-table-with-request-to-disaply-6-categories-only-one-is/m-p/786146#M250965</link>
      <description>&lt;P&gt;PROC PARETO does this for you, if you have SAS/QC licensed. Here is an example: &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/qcug/qcug_pareto_examples01.htm" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmmvacdc/9.4/qcug/qcug_pareto_examples01.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would want to use the MAXNCAT=5 option to get counts for the highest 5 categories, and then the remaining categories would be set to whatever name is specified by the OTHER= option.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Dec 2021 11:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Freq-table-with-request-to-disaply-6-categories-only-one-is/m-p/786146#M250965</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-15T11:51:17Z</dc:date>
    </item>
  </channel>
</rss>

