Hi!
I have a dataset with two numerical variables and 3 categorical variables. I need to sort the results of my proc tabulate in descending order based on the numeric variable I use as the analysis variable in the proc tabulate. I've tried various ways to pre-sort the dataset but I can't get any results. I'm attaching my code in case you can give me a hand. Thank you so much in advance!
Your code identifies TWO analysis variables, each of whose SUM you want to display in the table. That means it would display two columns.
But, instead of ordering the table rows based on the row classification variable (ascending or descending or formatted), I think you want to order based on descending SUM of an analysis variable.
"descending order based on the numeric variable I use as the analysis variable in the proc tabulate"
Do I understand correctly? If I don't you can ignore everything below.
But if so, then I ask:
To do this, I think you will have to do something like
You can create a data set using Proc Tabulate that contains the elements of the report plus some layout information.
Use the OUT=option.
It may be possible to sort that data set in the order of the statistics plus appropriate layout information and display the results though likely NOT using proc tabulate again.
You will need to look at the _TYPE_ _PAGE_ and _TABLE_ variables that hold the layout information and use them in your sort.
Without data and an example of the expected output for that data it isn't going to be possible to provide working code.
The CLASS statement in PROC TABULATE has a DESCENDING option, did you try that?
Your code identifies TWO analysis variables, each of whose SUM you want to display in the table. That means it would display two columns.
But, instead of ordering the table rows based on the row classification variable (ascending or descending or formatted), I think you want to order based on descending SUM of an analysis variable.
"descending order based on the numeric variable I use as the analysis variable in the proc tabulate"
Do I understand correctly? If I don't you can ignore everything below.
But if so, then I ask:
To do this, I think you will have to do something like
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.