<?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: proc freq in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-freq/m-p/490658#M72128</link>
    <description>&lt;P&gt;It depends partly on how you define your percentages but I'm a fan of the double proc freq for that type of work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SQL with distinct works as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I illustrate both options here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/count_distinct_by_group.sas" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/count_distinct_by_group.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;*Double PROC FREQ;
proc freq data=sashelp.cars noprint;
table origin * make / out=origin_make;
run;

proc freq data=origin_make noprint;
table origin / out= distinct_freq;
run;

title 'PROC FREQ';
proc print data=distinct_freq;
run;
title 'PROC SQL';
proc print data=distinct_sql;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the percentages in the output data set make sure to specify OUTPCT or OUTPERCENT (can't recall which is correct) to capture the percents.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Aug 2018 22:31:45 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-08-28T22:31:45Z</dc:date>
    <item>
      <title>proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-freq/m-p/490561#M72121</link>
      <description>&lt;P&gt;My data is as follow:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;office id&lt;/TD&gt;&lt;TD&gt;staff id&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;U790&lt;/TD&gt;&lt;TD&gt;452363&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;U797&lt;/TD&gt;&lt;TD&gt;452354&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;U797&lt;/TD&gt;&lt;TD&gt;452363&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;U790&lt;/TD&gt;&lt;TD&gt;452356&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;U790&lt;/TD&gt;&lt;TD&gt;452363&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;U790&lt;/TD&gt;&lt;TD&gt;452336&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;U797&lt;/TD&gt;&lt;TD&gt;452346&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;U797&lt;/TD&gt;&lt;TD&gt;452383&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;U100&lt;/TD&gt;&lt;TD&gt;452363&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to perform count proc freq and get table as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;office id&lt;/TD&gt;&lt;TD&gt;count of staff&lt;/TD&gt;&lt;TD&gt;percentage of staff id for each office id&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;U100&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;11.11%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;U790&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;44.44%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;U797&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;44.44%&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did proc freq data=have; table staff_id; by office_id; run; I got a weird result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 17:36:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-freq/m-p/490561#M72121</guid>
      <dc:creator>pmpradhan</dc:creator>
      <dc:date>2018-08-28T17:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-freq/m-p/490564#M72122</link>
      <description>&lt;P&gt;Your code looks correct. What is your 'weird result'?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/105450"&gt;@pmpradhan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;My data is as follow:&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;office id&lt;/TD&gt;
&lt;TD&gt;staff id&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;U790&lt;/TD&gt;
&lt;TD&gt;452363&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;U797&lt;/TD&gt;
&lt;TD&gt;452354&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;U797&lt;/TD&gt;
&lt;TD&gt;452363&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;U790&lt;/TD&gt;
&lt;TD&gt;452356&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;U790&lt;/TD&gt;
&lt;TD&gt;452363&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;U790&lt;/TD&gt;
&lt;TD&gt;452336&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;U797&lt;/TD&gt;
&lt;TD&gt;452346&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;U797&lt;/TD&gt;
&lt;TD&gt;452383&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;U100&lt;/TD&gt;
&lt;TD&gt;452363&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to perform count proc freq and get table as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;office id&lt;/TD&gt;
&lt;TD&gt;count of staff&lt;/TD&gt;
&lt;TD&gt;percentage of staff id for each office id&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;U100&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;11.11%&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;U790&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;44.44%&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;U797&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;44.44%&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did proc freq data=have; table staff_id; by office_id; run; I got a weird result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 17:59:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-freq/m-p/490564#M72122</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-08-28T17:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-freq/m-p/490571#M72123</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/105450"&gt;@pmpradhan&lt;/a&gt;&amp;nbsp;I'm afraid&lt;EM&gt;&lt;STRONG&gt; for your expected result&lt;/STRONG&gt;&lt;/EM&gt; you do not need by group&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (officeid	staffid) ($);
cards;
U790	452363
U797	452354
U797	452363
U790	452356
U790	452363
U790	452336
U797	452346
U797	452383
U100	452363
;
proc freq data=have;
tables officeid/out=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Aug 2018 18:27:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-freq/m-p/490571#M72123</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-28T18:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-freq/m-p/490646#M72124</link>
      <description>&lt;P&gt;Thanks for the code. How does this handle the duplicates counts of staffid?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 21:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-freq/m-p/490646#M72124</guid>
      <dc:creator>pmpradhan</dc:creator>
      <dc:date>2018-08-28T21:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-freq/m-p/490649#M72125</link>
      <description>&lt;P&gt;the result that I got was something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;U100 &lt;SPAN&gt;452363 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;U790&amp;nbsp;&lt;SPAN&gt;452363 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;U790&amp;nbsp;452356 1&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;U790&amp;nbsp;452336 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;and so forth&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If proc sql&amp;nbsp;allows me to create the percentage column that is fine too.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 21:56:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-freq/m-p/490649#M72125</guid>
      <dc:creator>pmpradhan</dc:creator>
      <dc:date>2018-08-28T21:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-freq/m-p/490651#M72126</link>
      <description>&lt;P&gt;Can you please clarify the results you want for your sample?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 21:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-freq/m-p/490651#M72126</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-28T21:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-freq/m-p/490652#M72127</link>
      <description>something along the lines of&lt;BR /&gt;proc sql;&lt;BR /&gt;create table x as&lt;BR /&gt;select distinct officeid,&lt;BR /&gt;count distinct staffid,&lt;BR /&gt;(calculated officeid/calculated staffid)*100 from have;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;the code might not be accurate but something along those lines should work.</description>
      <pubDate>Tue, 28 Aug 2018 22:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-freq/m-p/490652#M72127</guid>
      <dc:creator>pmpradhan</dc:creator>
      <dc:date>2018-08-28T22:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-freq/m-p/490658#M72128</link>
      <description>&lt;P&gt;It depends partly on how you define your percentages but I'm a fan of the double proc freq for that type of work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SQL with distinct works as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I illustrate both options here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/count_distinct_by_group.sas" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/count_distinct_by_group.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;*Double PROC FREQ;
proc freq data=sashelp.cars noprint;
table origin * make / out=origin_make;
run;

proc freq data=origin_make noprint;
table origin / out= distinct_freq;
run;

title 'PROC FREQ';
proc print data=distinct_freq;
run;
title 'PROC SQL';
proc print data=distinct_sql;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the percentages in the output data set make sure to specify OUTPCT or OUTPERCENT (can't recall which is correct) to capture the percents.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 22:31:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-freq/m-p/490658#M72128</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-08-28T22:31:45Z</dc:date>
    </item>
  </channel>
</rss>

