BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Davanden
Obsidian | Level 7

I want to make a report that shows the sums of four columns plus the ratios or percentages of three of the sums to the other sum.  Is it possible to do this in one TABULATE or REPORT step?  See the code for what I have so far.  What I want to add is the sums of b, c, and d as a percentage of the sum of a, for each row--the last three columns of the example table.

 

It's easy to do this in two steps, but I was wondering if I could do this in only one.

 

/*what I have so far */
PROC TABULATE DATA=STUFF;
     WEIGHT weight;
     CLASS rowvar;
     VAR a b c d;
     TABLE rowvar,
          (a b c d)*SUM
     ;
RUN;

 

Rowvarabcdbcd
 sumsumsumsumpct?pct?pct?
Able2053425.015.020.0
Baker30106833.320.026.7
Charlie401591237.522.530.0
Delta5020121640.024.032.0

 

--Dav

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Without example data it is hard to test code but if I understatnd what you want this may work:

 

(a b c d)*SUM b*Pctsum<a> c*Pctsum<a> d*Pctsum<a>

 

View solution in original post

3 REPLIES 3
ballardw
Super User

Without example data it is hard to test code but if I understatnd what you want this may work:

 

(a b c d)*SUM b*Pctsum<a> c*Pctsum<a> d*Pctsum<a>

 

Davanden
Obsidian | Level 7

Thank you.  I was hoping it was something simple.  i confess that I always have trouble thinking about how percentages work in PROC TABULATE.

 

--Dav

ballardw
Super User

For a special treat see what happens if you use COLPCTSUM or ROWPCTSUM instead of PCTSUM. HINT: SAVE your data and program code before executing the code. Unless they have fixed the compiler recently to check for that usage you may generate a SAS system crash.

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
  • 3 replies
  • 1264 views
  • 0 likes
  • 2 in conversation