BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I want create report using proc report.

Please see the code.

I want to add one more column of PCT from total for each team.

For category a we need to get 100/550=18%

For category a we need to get 450/550=82%

Data tbl;
input ID  Team $ Country  $ sales;
cards;
1  a UK 10
2  a UK 20
3  a UK 30
4  a USA 40
5  b UK 50
6  b UK  60
7  b USA  70
8  b USA  80
9  b USA 90
10 b USA 100
;
run;
 Proc report data=tbl nowd;
   columns Team Country,(sales=salespctsum)  ;
   define Team/ group   ;
   define Country/across   order=formatted ;
   define salespctsum / pctsum  format=percent9.1  ;
rbreak after/ summarize;
run;
2 REPLIES 2
Ksharp
Super User

Since you want a summary table, why not using PROC TABULATE ?

 

Data tbl;
input ID  Team $ Country  $ sales;
cards;
1  a UK 10
2  a UK 20
3  a UK 30
4  a USA 40
5  b UK 50
6  b UK  60
7  b USA  70
8  b USA  80
9  b USA 90
10 b USA 100
;
run;
 Proc tabulate data=tbl ;
   class Team Country;
   var sales;
   table team all,country*sales*colpctsum=' ' sales='total'*pctsum=' ';
run;
Cynthia_sas
Diamond | Level 26

Hi:
For a simple PCTSUM, you don't need to move to TABULATE, although that does give you more percent keyword choices. You only need to modify your PROC REPORT to use SALES again on the report, but not UNDER COUNTRY, as shown below:
Cynthia

 

 
Proc report data=tbl nowd;
   columns Team Country,(sales=salespctsum) sales=tot sales=cpct;
   define Team/ group   ;
   define sales / sum;
   define Country/across 'Country Percent'  order=formatted ;
   define salespctsum / pctsum  format=percent9.1  ;
   define tot / 'Total';
   define cpct / pctsum format=percent9.1;
rbreak after/ summarize;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 945 views
  • 0 likes
  • 3 in conversation