12m ago
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
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.
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.
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.
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.
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.