BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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
SAS Super FREQ

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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 619 views
  • 0 likes
  • 3 in conversation