DATA Step, Macro, Functions and more

Ordering frequences in proc tabulate (order=freq)

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

Ordering frequences in proc tabulate (order=freq)

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

 


Accepted Solutions
Solution
‎12-21-2016 04:40 AM
Super User
Posts: 11,343

Re: Ordering frequences in proc tabulate (order=freq)

Posted in reply to Daniela_P

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


All Replies
Super Contributor
Posts: 266

Re: Ordering frequences in proc tabulate (order=freq)

[ Edited ]
Posted in reply to Daniela_P
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;
Contributor
Posts: 23

Re: Ordering frequences in proc tabulate (order=freq)

I tried it, but It doesn't work.
Super Contributor
Posts: 308

Re: Ordering frequences in proc tabulate (order=freq)

[ Edited ]
Posted in reply to Daniela_P

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.

 

 

 

Contributor
Posts: 23

Re: Ordering frequences in proc tabulate (order=freq)

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.

Solution
‎12-21-2016 04:40 AM
Super User
Posts: 11,343

Re: Ordering frequences in proc tabulate (order=freq)

Posted in reply to Daniela_P

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.

Contributor
Posts: 23

Re: Ordering frequences in proc tabulate (order=freq)

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.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 316 views
  • 1 like
  • 4 in conversation