BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
RandoDando
Pyrite | Level 9

I have data which has already been aggregated like this:

 

Category Groups People
A 23 235
B 45 754
C 12 89

 

And I want something like this (prefer Proc Report for the bells and whistles)

Category Groups Groups Percent People People Percent
A 23 28.8% 235 21.8%
B 45 56.3% 754 69.9%
C 12 15.0% 89 8.3%
Total 80 100.0% 1078 100.0%

 

All the examples I can find online seem to use dis-aggregated data.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

To get multiple statistics from a single variable repeat it with a new column name and then request the statistic:

 

data have;
   input Category $	Groups 	People;
datalines;
A 	23 	235
B 	45 	754
C 	12 	89
;

proc report data=have;
   columns category groups groups=grouppct people people=peoplepct;
   define category /group;
   define groups/ analysis sum;
   define grouppct /analysis pctsum;
   define people/ analysis sum;
   define peoplepct/ analysis pctsum;
run;

However if you want anything that measures dispersion such as standard deviation or range of value you would want to use disaggregated data.

 


@RandoDando wrote:

I have data which has already been aggregated like this:

 

Category Groups People
A 23 235
B 45 754
C 12 89

 

And I want something like this (prefer Proc Report for the bells and whistles)

Category Groups Groups Percent People People Percent
A 23 28.8% 235 21.8%
B 45 56.3% 754 69.9%
C 12 15.0% 89 8.3%
Total 80 100.0% 1078 100.0%

 

All the examples I can find online seem to use dis-aggregated data.


 

 

View solution in original post

3 REPLIES 3
ballardw
Super User

To get multiple statistics from a single variable repeat it with a new column name and then request the statistic:

 

data have;
   input Category $	Groups 	People;
datalines;
A 	23 	235
B 	45 	754
C 	12 	89
;

proc report data=have;
   columns category groups groups=grouppct people people=peoplepct;
   define category /group;
   define groups/ analysis sum;
   define grouppct /analysis pctsum;
   define people/ analysis sum;
   define peoplepct/ analysis pctsum;
run;

However if you want anything that measures dispersion such as standard deviation or range of value you would want to use disaggregated data.

 


@RandoDando wrote:

I have data which has already been aggregated like this:

 

Category Groups People
A 23 235
B 45 754
C 12 89

 

And I want something like this (prefer Proc Report for the bells and whistles)

Category Groups Groups Percent People People Percent
A 23 28.8% 235 21.8%
B 45 56.3% 754 69.9%
C 12 15.0% 89 8.3%
Total 80 100.0% 1078 100.0%

 

All the examples I can find online seem to use dis-aggregated data.


 

 

RandoDando
Pyrite | Level 9

Thanks for that, it worked.  I added the rbreak /summarize statement at the end of this, but I would like to have the label "Total" in that summary row in only the first column.  Is that possible?    I tried this, but obviously, it adds the label in each column.

 

rbreak after/summarize style={pretext="Total"};

 Would also want the label to be indented to the left to align with values in Category.

RandoDando
Pyrite | Level 9

Nevermind.  I got it.

Compute after;
Category = "Total";
endcomp;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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