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

Ordering frequences in proc tabulate (order=freq)

Dear experts,

I don't succeed in ordering frequences when using var and statistic "sum".

Am I mistaking something?

 

Here's the program:

 

proc tabulate data=sashelp.class f=6.;
CLASS height/order=freq;
var weight;
table height  all,weight*sum/rts=25 condense;
run;

 

 

Here's the result:

                                Weight    
                             |------------|
                                  Sum      
|----------------------- ------------|
 Height                               
|-----------------------|             
 62.5                             197
|----------------------- ------------|
 66.5                             224
|----------------------- ------------|
 69                               113
|----------------------- ------------|
 56.5                              84
|----------------------- ------------|
 65.3                              98
|----------------------- ------------|
 62.8                             103
|----------------------- ------------|
 63.5                             103
|----------------------- ------------|
 57.3                              83
|----------------------- ------------|
 59.8                              85
|----------------------- ------------|
 59                               100
|----------------------- ------------|
 51.3                              51
|----------------------- ------------|
 64.3                              90
|----------------------- ------------|
 56.3                              77
|----------------------- ------------|
 72                               150
|----------------------- ------------|
 64.8                             128
|----------------------- ------------|
 67                               133
|----------------------- ------------|
 57.5                              85
|----------------------- ------------|
 All                             1901

 

As you can see, frequences are not ordered.

I cannot use proc freq, because I'd like to add some variables in the heading.

 

Thank you all,

Daniela

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I don't believe you have quite adequately described what your desired order may be. Are you trying to order by the value of the statistic SUM? That is not an option in Tabulate. You would have to summarize the data first and then have a variable that could apply order to.

View solution in original post

6 REPLIES 6
RahulG
Barite | Level 11
Try option order=internal; proc tabulate data=sashelp.class f=6. ; CLASS height/order=internal; var weight; table height all,weight*sum/rts=25 condense ; run;
Daniela_P
Obsidian | Level 7
I tried it, but It doesn't work.
Loko
Barite | Level 11

Hello,

 

The documentation states:

 

FREQ - orders values by descending frequency count.

 

Thus , in your example the count  is 1 for all the observations listed except for height=62.5 which is twice met therefore is listed first. You may have expected the results to be orderred by the sum but the results are ordered by the frequency count.

 

 

 

Daniela_P
Obsidian | Level 7

Thank you very much for the clarification. Now is clearly for me why the output has such an order.

 

I've already solved my problem by applying a 'multilabel notsorted' format to the variable in the order I want, but I'd still like to find a easier way to order the variable (directly from the tabulate).

 

Is there any method to solve my necessity?

 

Thank you in advance.

ballardw
Super User

I don't believe you have quite adequately described what your desired order may be. Are you trying to order by the value of the statistic SUM? That is not an option in Tabulate. You would have to summarize the data first and then have a variable that could apply order to.

Daniela_P
Obsidian | Level 7
Yes, I'd have liked to order by the value of the statistic SUM... now I know it isn't the way.
Thank you for the suggestion. I'll try it.

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
  • 6 replies
  • 2679 views
  • 1 like
  • 4 in conversation