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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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