<?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: Help on Proc Tabulate to get the Total value by Percentage. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Help-on-Proc-Tabulate-to-get-the-Total-value-by-Percentage/m-p/18305#M3565</link>
    <description>In this case, I believe the "ALL" statement will not give you what you need. You could bring the x variable into a proc report and use a compute block. Or you could calculate the totals before displaying the data with proc tabulate. Here's a sample way to the second approach.&lt;BR /&gt;
&lt;BR /&gt;
proc format;&lt;BR /&gt;
	value $period_group (multilabel)&lt;BR /&gt;
		'01'='01'&lt;BR /&gt;
		'02'='02'&lt;BR /&gt;
		'03'='03'&lt;BR /&gt;
		'04'='04'&lt;BR /&gt;
		'05'='05'&lt;BR /&gt;
		'06'='06'&lt;BR /&gt;
		'07'='07'&lt;BR /&gt;
		'08'='08'&lt;BR /&gt;
		'09'='09'&lt;BR /&gt;
		'10'='10'&lt;BR /&gt;
		'11'='11'&lt;BR /&gt;
		'12'='12'&lt;BR /&gt;
		'01'-'12'='Total';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
****  Create Sample Data  *****;&lt;BR /&gt;
data sample_data;&lt;BR /&gt;
	do i=1 to 12;&lt;BR /&gt;
		do j=1 to 20;&lt;BR /&gt;
		month=i;&lt;BR /&gt;
		a= int(100*rand('uniform')); &lt;BR /&gt;
		x= int(100*rand('uniform'));&lt;BR /&gt;
&lt;BR /&gt;
		*** make the denominator bigger than the numerator  ***;&lt;BR /&gt;
		if x &amp;gt; a then 	output;&lt;BR /&gt;
		end;&lt;BR /&gt;
	end;&lt;BR /&gt;
&lt;BR /&gt;
	keep month a x;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=sample_data;&lt;BR /&gt;
	by month;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
***** Limit sample data to one row per period *****;&lt;BR /&gt;
data limit_data;&lt;BR /&gt;
	length period $2;&lt;BR /&gt;
	set sample_data;&lt;BR /&gt;
	by month;&lt;BR /&gt;
&lt;BR /&gt;
	if first.month;&lt;BR /&gt;
	&lt;BR /&gt;
	***  create period variable  ***;&lt;BR /&gt;
	if 1 le month le 9 then period='0'||left(month);&lt;BR /&gt;
	else if 10-12 then period=month;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc summary data=limit_data;&lt;BR /&gt;
	class period /mlf;&lt;BR /&gt;
	format period $period_group.;&lt;BR /&gt;
	var a x;&lt;BR /&gt;
	types period ;&lt;BR /&gt;
	output out=group_periods (drop=_type_ _freq_)sum=;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data abc;&lt;BR /&gt;
	set group_periods;&lt;BR /&gt;
&lt;BR /&gt;
	*** b calculation  ***;&lt;BR /&gt;
	b=(a/x);&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc tabulate data=abc;&lt;BR /&gt;
	class period ;&lt;BR /&gt;
	format period ;&lt;BR /&gt;
	var a b;&lt;BR /&gt;
	table a*f=comma9.0 b*f=percent9.2, period=' '*sum=' ' ;&lt;BR /&gt;
	keylabel sum=' ';&lt;BR /&gt;
&lt;BR /&gt;
run;</description>
    <pubDate>Mon, 28 Feb 2011 18:33:45 GMT</pubDate>
    <dc:creator>AndyJ</dc:creator>
    <dc:date>2011-02-28T18:33:45Z</dc:date>
    <item>
      <title>Help on Proc Tabulate to get the Total value by Percentage.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-on-Proc-Tabulate-to-get-the-Total-value-by-Percentage/m-p/18304#M3564</link>
      <description>Hi SAS Gurus,&lt;BR /&gt;
&lt;BR /&gt;
This would be my 2nd thread here. I'll waste no time here. My situation is as follows:&lt;BR /&gt;
&lt;BR /&gt;
Basically I have already done a proc tabulate to tabulate the values for var A together with var B, in 12 period (can be considered 12 months) and then total up the values.&lt;BR /&gt;
&lt;BR /&gt;
proc tabulate data = abc;&lt;BR /&gt;
class period;&lt;BR /&gt;
var a b;&lt;BR /&gt;
table a*f=comma9.1 b*f=percentn9.2, period=' '*SUM=' ' ALL='Total'*SUM=' ';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
The result is as below:&lt;BR /&gt;
Period       1               2                  3                  4               5.........  12         Total&lt;BR /&gt;
A             12              42                32               11               43........  71          425&lt;BR /&gt;
B            21.1%        38.2%          12.5%          3.0%     11.1%....41.1%      230.2%&lt;BR /&gt;
&lt;BR /&gt;
My problem is, whatever i do or try to change, the total will always add up especially for var B, which is not correct as the correct value should be the calculation between 2 other variables (which are A/x) that are used to calculate percentage of B. &lt;BR /&gt;
&lt;BR /&gt;
Is there any anything I can do to correct the total % of B so that it will relect the correct % value (total A divided by total x) using proc tabulate?&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your time.</description>
      <pubDate>Mon, 28 Feb 2011 10:55:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-on-Proc-Tabulate-to-get-the-Total-value-by-Percentage/m-p/18304#M3564</guid>
      <dc:creator>KYW</dc:creator>
      <dc:date>2011-02-28T10:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: Help on Proc Tabulate to get the Total value by Percentage.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-on-Proc-Tabulate-to-get-the-Total-value-by-Percentage/m-p/18305#M3565</link>
      <description>In this case, I believe the "ALL" statement will not give you what you need. You could bring the x variable into a proc report and use a compute block. Or you could calculate the totals before displaying the data with proc tabulate. Here's a sample way to the second approach.&lt;BR /&gt;
&lt;BR /&gt;
proc format;&lt;BR /&gt;
	value $period_group (multilabel)&lt;BR /&gt;
		'01'='01'&lt;BR /&gt;
		'02'='02'&lt;BR /&gt;
		'03'='03'&lt;BR /&gt;
		'04'='04'&lt;BR /&gt;
		'05'='05'&lt;BR /&gt;
		'06'='06'&lt;BR /&gt;
		'07'='07'&lt;BR /&gt;
		'08'='08'&lt;BR /&gt;
		'09'='09'&lt;BR /&gt;
		'10'='10'&lt;BR /&gt;
		'11'='11'&lt;BR /&gt;
		'12'='12'&lt;BR /&gt;
		'01'-'12'='Total';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
****  Create Sample Data  *****;&lt;BR /&gt;
data sample_data;&lt;BR /&gt;
	do i=1 to 12;&lt;BR /&gt;
		do j=1 to 20;&lt;BR /&gt;
		month=i;&lt;BR /&gt;
		a= int(100*rand('uniform')); &lt;BR /&gt;
		x= int(100*rand('uniform'));&lt;BR /&gt;
&lt;BR /&gt;
		*** make the denominator bigger than the numerator  ***;&lt;BR /&gt;
		if x &amp;gt; a then 	output;&lt;BR /&gt;
		end;&lt;BR /&gt;
	end;&lt;BR /&gt;
&lt;BR /&gt;
	keep month a x;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=sample_data;&lt;BR /&gt;
	by month;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
***** Limit sample data to one row per period *****;&lt;BR /&gt;
data limit_data;&lt;BR /&gt;
	length period $2;&lt;BR /&gt;
	set sample_data;&lt;BR /&gt;
	by month;&lt;BR /&gt;
&lt;BR /&gt;
	if first.month;&lt;BR /&gt;
	&lt;BR /&gt;
	***  create period variable  ***;&lt;BR /&gt;
	if 1 le month le 9 then period='0'||left(month);&lt;BR /&gt;
	else if 10-12 then period=month;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc summary data=limit_data;&lt;BR /&gt;
	class period /mlf;&lt;BR /&gt;
	format period $period_group.;&lt;BR /&gt;
	var a x;&lt;BR /&gt;
	types period ;&lt;BR /&gt;
	output out=group_periods (drop=_type_ _freq_)sum=;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data abc;&lt;BR /&gt;
	set group_periods;&lt;BR /&gt;
&lt;BR /&gt;
	*** b calculation  ***;&lt;BR /&gt;
	b=(a/x);&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc tabulate data=abc;&lt;BR /&gt;
	class period ;&lt;BR /&gt;
	format period ;&lt;BR /&gt;
	var a b;&lt;BR /&gt;
	table a*f=comma9.0 b*f=percent9.2, period=' '*sum=' ' ;&lt;BR /&gt;
	keylabel sum=' ';&lt;BR /&gt;
&lt;BR /&gt;
run;</description>
      <pubDate>Mon, 28 Feb 2011 18:33:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-on-Proc-Tabulate-to-get-the-Total-value-by-Percentage/m-p/18305#M3565</guid>
      <dc:creator>AndyJ</dc:creator>
      <dc:date>2011-02-28T18:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Help on Proc Tabulate to get the Total value by Percentage.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-on-Proc-Tabulate-to-get-the-Total-value-by-Percentage/m-p/18306#M3566</link>
      <description>Hi Andy.&lt;BR /&gt;
Thank you for your response. I am now trying to apply your logic into my program. Nice data generation there I must say.&lt;BR /&gt;
&lt;BR /&gt;
Will let you know if there's any further issue regarding this.</description>
      <pubDate>Tue, 01 Mar 2011 08:29:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-on-Proc-Tabulate-to-get-the-Total-value-by-Percentage/m-p/18306#M3566</guid>
      <dc:creator>KYW</dc:creator>
      <dc:date>2011-03-01T08:29:17Z</dc:date>
    </item>
  </channel>
</rss>

