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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 459 views
  • 0 likes
  • 2 in conversation