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

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
Red5
Blue8
Yellow2
Green3
Total 18

 

1 ACCEPTED SOLUTION

Accepted Solutions
LeonidBatkhan
Lapis Lazuli | Level 10

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:

PROC_REPORT_OUTPUT.JPG

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.)

 

 

View solution in original post

3 REPLIES 3
Reeza
Super User

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

 


 

LeonidBatkhan
Lapis Lazuli | Level 10

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:

PROC_REPORT_OUTPUT.JPG

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.)

 

 

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
  • 754 views
  • 0 likes
  • 3 in conversation