I'm trying to do something simple but am struggling.
I'd like to create a simple one way frequency table with column total. I'd like to customize the order of the labels (not just by frequency) and change the Frequency label to Number. So the table would look like this: Thanks!
Number | |
Red | 5 |
Blue | 8 |
Yellow | 2 |
Green | 3 |
Total | 18 |
Here is how you can do it with PROC FREQ and PROC REPORT:
proc freq data=sashelp.cars noprint;
tables make / out=A;
run;
proc report data=A style(summary)=header;
column make count;
define make / order;
define count / analysis 'Number';
rbreak after / summarize;
compute after;
make = 'Total';
endcomp;
run;
Your output will look like this:
After PROC PRINT and before PROC REPORT you can sort your MAKE variable as you want. (I am not sure why you would need 2 empty cells at the top of your table.)
Customizing the order is a bit more complicated, you can use ORDER=DATA to keep the order your data is in though. Sometimes if you need custom order you'll need to add another variable to control the order. Otherwise this is a pretty straightforward request, see below which replicates it for SASHELP.CLASS data set.
proc tabulate data=sashelp.class;
class age;
table (age='' all='Total'), N='Number';
run;
@JenMMerc wrote:
I'm trying to do something simple but am struggling.
I'd like to create a simple one way frequency table with column total. I'd like to customize the order of the labels (not just by frequency) and change the Frequency label to Number. So the table would look like this: Thanks!
Number Red 5 Blue 8 Yellow 2 Green 3 Total 18
Here is how you can do it with PROC FREQ and PROC REPORT:
proc freq data=sashelp.cars noprint;
tables make / out=A;
run;
proc report data=A style(summary)=header;
column make count;
define make / order;
define count / analysis 'Number';
rbreak after / summarize;
compute after;
make = 'Total';
endcomp;
run;
Your output will look like this:
After PROC PRINT and before PROC REPORT you can sort your MAKE variable as you want. (I am not sure why you would need 2 empty cells at the top of your table.)
This worked! Thanks!
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.