Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating percentages of a population within a proc report 1

Status
Not open for further replies.

JamesH122

Technical User
Aug 14, 2007
4
GB
I'm producing a series of reports from one dataset using proc report. In each report there are the volume of individuals by category - I want to get each one of these volumes output as a pecentage of the total.
e.g.

Vol Perc
10 ?%
10 ?%
10 ?%
10 ?%
40 100%

Is there anyway of doing this within the proc report or am I going to have create separate data sets for each series of reports and create a total number of Volumes within that?

Many thanks

James
 
I don't fully understand your problem here, but I think that this article might help you out.


I hit something similar when I was trying to do percentages across a dataset. I think in the end I actually ran a step prior to that to get a total count into a macro variable, then used that macro variable to calculate the percentages.
Something like this:-
Code:
proc sql noprint;  /* Noprint supresses printed output */
  select sum(vol)
  INTO :TOT_VOL
  from mydset 
  ;
quit;

data mydset2;
  set mydset;

  pct = vol/&TOT_VOL ;
run;
You could also do this last step in a compute statement in your proc report if you're comfortable with proc report. I quite often prefer to do it in a datastep befor the proc report so that I can see the actual results in a dataset, makes it a bit easier to debug at times.
If you DO choose to do this in the Proc Report step, make sure that your calculated variable (PCT) appears AFTER the variable it depends on (VOL) in the list of columns, otherwise you'll just get missing values as your result. This is because Proc Report, as it processes each column, only knows about the previous columns, not ones further along its list.
Let me know how it goes.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Thanks for your reply Chris.

The article you attached had just the code I was looking for on page 15 - effectively it does what a proc freq does but within the proc report and you can accumulate the percentages on a number of different columns.

This is a very useful bit of code - nice one!

Cheers

James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top