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.
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.
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.
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.
Nevermind. I got it.
Compute after;
Category = "Total";
endcomp;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.