<?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: Percentages in SAS in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579512#M34412</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271494"&gt;@jffeudo86&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Using coding. Not really sure how to use proc freq. Can I get the code please?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One way to get your shown output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc freq data=have;
   tables month / nocum;
run;&lt;/PRE&gt;
&lt;P&gt;You didn't share the name of your data set. Use your name where I am using Have. If the name of your variable holding month values is something other than month then use your name.&lt;/P&gt;
&lt;P&gt;Proc freq by default reports percentages to 2 decimals. If that is unacceptable then use on of the other procedures that allows more output control. Or send the output to data set and use a format to control decimals:&lt;/P&gt;
&lt;PRE&gt;Proc freq data=have noprint;
   tables month / out=work.summary;
run;

Proc print data=work.summary noobs;
   var month count percent;
   format percent f3.0;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Aug 2019 15:36:44 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-08-07T15:36:44Z</dc:date>
    <item>
      <title>Percentages in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579499#M34406</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I get the percentages of a variable against the total?&amp;nbsp; This is probably so simple but I'm not a SAS expert.&amp;nbsp; Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's an example of data:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Month&lt;/TD&gt;&lt;TD&gt;Variable2&lt;/TD&gt;&lt;TD&gt;Variable3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;JAN&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;JAN&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;JAN&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;z&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FEB&lt;/TD&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;MAR&lt;/TD&gt;&lt;TD&gt;zz&lt;/TD&gt;&lt;TD&gt;av&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;MAR&lt;/TD&gt;&lt;TD&gt;d&lt;/TD&gt;&lt;TD&gt;e&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 my report to look like:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Month&lt;/TD&gt;&lt;TD&gt;Count&lt;/TD&gt;&lt;TD&gt;Pct&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;JAN&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;50%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FEB&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;17%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;MAR&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;33%&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;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2019 20:45:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579499#M34406</guid>
      <dc:creator>jffeudo86</dc:creator>
      <dc:date>2019-08-06T20:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: Percentages in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579500#M34407</link>
      <description>Are you using the GUI or coding? If coding use PROC FREQ, if using the GUI, try a Summary or CrossTab task to generate the summary table.</description>
      <pubDate>Tue, 06 Aug 2019 20:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579500#M34407</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-08-06T20:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: Percentages in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579502#M34408</link>
      <description>Using coding. Not really sure how to use proc freq. Can I get the code please?&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Aug 2019 20:59:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579502#M34408</guid>
      <dc:creator>jffeudo86</dc:creator>
      <dc:date>2019-08-06T20:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: Percentages in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579510#M34411</link>
      <description>&lt;P&gt;Can you provide real numbers? It is not obvious how the values of variable2 and variable3 are turned into your percentages.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2019 21:32:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579510#M34411</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-06T21:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: Percentages in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579512#M34412</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271494"&gt;@jffeudo86&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Using coding. Not really sure how to use proc freq. Can I get the code please?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One way to get your shown output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc freq data=have;
   tables month / nocum;
run;&lt;/PRE&gt;
&lt;P&gt;You didn't share the name of your data set. Use your name where I am using Have. If the name of your variable holding month values is something other than month then use your name.&lt;/P&gt;
&lt;P&gt;Proc freq by default reports percentages to 2 decimals. If that is unacceptable then use on of the other procedures that allows more output control. Or send the output to data set and use a format to control decimals:&lt;/P&gt;
&lt;PRE&gt;Proc freq data=have noprint;
   tables month / out=work.summary;
run;

Proc print data=work.summary noobs;
   var month count percent;
   format percent f3.0;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2019 15:36:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579512#M34412</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-07T15:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: Percentages in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579525#M34415</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271494"&gt;@jffeudo86&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (Month	Variable2	Variable3) ($);
cards;
JAN	x	y
JAN	x	x
JAN	y	z
FEB	a	b
MAR	zz	av
MAR	d	e
;

proc sql;
create table want as
select month,count(month) as count,calculated count/c as pct  format=percent.
from have a,(select count(*) as c from have) b
group by month ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Aug 2019 22:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579525#M34415</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-06T22:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Percentages in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579526#M34416</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (Month	Variable2	Variable3) ($);
cards;
JAN	x	y
JAN	x	x
JAN	y	z
FEB	a	b
MAR	zz	av
MAR	d	e
;

data want;
do count=1 by 1 until(last.month);
set have nobs=nobs;
by month notsorted;
end;
pct=count/nobs;
format pct percent.;
drop variable:;	/*drop unwanted variables*/
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Aug 2019 22:57:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579526#M34416</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-06T22:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: Percentages in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579530#M34417</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
if _n_=1 then do;
   dcl hash H (dataset:'have(keep=month)',multidata:'y');
   h.definekey  ("month") ;
   h.definedone () ;
end;
do count=1 by 1 until(last.month);
set have;
by month notsorted;
end;
pct=count/h.num_items;
format pct percent.;
drop variable:;	/*drop unwanted variables*/
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Aug 2019 00:05:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579530#M34417</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-07T00:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: Percentages in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579595#M34422</link>
      <description>&lt;P&gt;Since you only need counts, this is the most efficient way (it avoids an additional read of the dataset for getting the whole count):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input month :$3.;
datalines;
JAN
JAN
JAN
FEB
MAR
MAR
;

proc sql noprint;
select nobs into :nobs from dictionary.tables
where libname ='WORK' and memname = 'HAVE';
quit;

data want;
set have;
by month notsorted;
retain count;
format pct percent5.;
if first.month
then count = 1;
else count + 1;
if last.month;
pct = count / &amp;amp;nobs.;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;month    count      pct

 JAN       3       50% 
 FEB       1       17% 
 MAR       2       33% 
&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Aug 2019 07:59:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579595#M34422</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-07T07:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: Percentages in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579666#M34423</link>
      <description>Thank you!</description>
      <pubDate>Wed, 07 Aug 2019 14:35:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Percentages-in-SAS/m-p/579666#M34423</guid>
      <dc:creator>jffeudo86</dc:creator>
      <dc:date>2019-08-07T14:35:00Z</dc:date>
    </item>
  </channel>
</rss>

