BookmarkSubscribeRSS Feed
deleted_user
Not applicable
HI all,
This is my data set..........

STAGE X Y Z TOTAL
A 1 2 2 5
B 3 6 9 18
C 1 2 5 8
TOTAL 5 10 16 31

By using rbreak in proc report we can get this 'TOTAL' row means we can summarize the data but instead of total i want percentage of data values with respect to total and with % sign along with it..Like..........

TOTAL 16.1% 32.2% 51.6% 100%

SO IS IT POSSIBLE?

Thanks for ur help...........
5 REPLIES 5
Tim_SAS
Barite | Level 11
Check out PROC REPORT's COMPUTE statement. Here's the doc: http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a000068725.htm. Also you can use the "Search Forum" link to find the answers given for very similar questions on this forum. Here's one such example: http://support.sas.com/forums/thread.jspa?messageID=18961䨑.

To display the percentages with a % sign, use the PERCENT. format.
deleted_user
Not applicable
Hi buddy,

thanks for ur help,

the examples which u have mentioned by that we can get the percentage in column but not in a row..I want to have the calculated percentage at the end of the dataset in a row...wat i hav done i hav preapred a new data set consisting of only one row to calculate the percentage..then i hav converted botth the datasets column into character format..after that using '||' i have attached % sign with the percenatge data set....and then i have appended both the datasets..but this is a long procedure..isnt there any simpler way?
Tim_SAS
Barite | Level 11
Use a COMPUTED column to compute the percentage. Use the FORMAT= option on the DEFINE statement of the column to associate the PERCENT. format with the column.
Cynthia_sas
SAS Super FREQ
Hi:
As much as I love PROC REPORT, I'm tempted to give this one to PROC TABULATE to produce the report. The ability to calculate percentages is very straightforward with TABULATE and usually produces the percentage you want either with a keyword percentage (ROWPCTSUM, COLPCTSUM, etc) or with a demoninator definition <denom> specified in the TABLE statement. PROC REPORT will do the job, but it does require some extra coding above and beyond basic PROC REPORT coding.

The only thing that TAB does that takes some getting used to is that it does an automatic multiply by 100 for percentages, which means that you cannot use the SAS pre-defined percent format. But with a PICTURE format, you can fix that easily and get a % into your cells. For example, given the data shown above, the TABULATE code would be as shown below. The PROC FORMAT step is defining a PICTURE format for use in the TABLE statement *f=pct. crossing, otherwise, the comma8 format will be used for all the other cells.

cynthia
[pre]
data getpct;
infile datalines;
input stage $ x y z total;
return;
datalines;
A 1 2 2 5
B 3 6 9 18
C 1 2 5 8
;
run;

proc format;
picture pct low-high='009.9%';
run;

ods listing close;
ods html file='c:\temp\getpct.html' style=sasweb;
proc tabulate data=getpct f=comma8.;
class stage;
var x y z total;
table stage all*pctsum*f=pct.,
x y z total / row=float;
keylabel sum=' '
pctsum = ' '
all='Percent';
run;
ods html close;
[/pre]
deleted_user
Not applicable
Thanks a lot Cynthia..U have solved my problem
and thanks to u too tim

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 779 views
  • 0 likes
  • 3 in conversation