BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

data test;

length ctr $25.;

infile datalines;

input ctr $ cnt cnt2;

return;

datalines;

 

4411 5 15

4455 15 66

4466 6 666

4477 11 42

;

run;

 

 

proc report = test nowd style(summary)=Header;

title 'test';

column ctr cnt cnt2 RTot PctTot;

define ctr /order order=data style (column)=Header ;

define cnt /sum f=comma6.;

define cnt2 /sum f=comma6.;

define PctTot/computed f=percent8.2;

define RTot /computed f=comma16. "Row Totals";

compute RTot;

RTot=sum(cnt.sum,cnt2.sum);/*row_tot*/

endcomp;

compute before;

 

sum=cnt.sum;

endcomp;

compute PctTot;

 

pcttot=cnt.sum/sum;

endcomp;

compute after;

 

ctr='Total';

endcomp;

rbreak after /summarize;

run;

It produces the results below.  I want the PCTTOT to be a measure of the cnt2/RTOT so for the first entry it should be 15/20 = 0.75 or 75%  So essentially I want to calculate at the row level across

ctr cnt cnt2 Row Totals PctTot
4411 5 15 20 13.51%
4455 15 66 81 40.54%
4466 6 666 672 16.22%
4477 11 42 53 29.73%
Total 37 789 826 100.0%
1 REPLY 1
ballardw
Super User

Please post code in a code box. Use the {I} or "running man" icon to open the box.

 

Your code as posted doesn't run as you are missing the data= on proc report;

Maybe:

 

proc report data = test nowd style(summary)=Header;
title 'test';
column ctr cnt cnt2 RTot PctTot;
define ctr /order order=data style (column)=Header ;
define cnt /sum f=comma6.;
define cnt2 /sum f=comma6.;
define PctTot/computed f=percent8.2;
define RTot /computed f=comma16. "Row Totals";
compute RTot; 
RTot=sum(cnt.sum,cnt2.sum);/*row_tot*/
endcomp;
compute before;
 
sum=cnt.sum;
endcomp;
compute PctTot;
 
pcttot=_c3_ / _c4_;
endcomp;
compute after;
 
ctr='Total';

endcomp;
rbreak after /summarize;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 305 views
  • 0 likes
  • 2 in conversation