BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello all:

I am attempting to find a way to specify the order of data within a column when the order is not simply ascending/descending. For example my dataset will have

COLUMN HEADER
W
X
Y
Z

But in my output I need the order to be

COLUMN HEADER
X
Z
Y
W

i.e. not alphabetical or reversed-alphabetical order, but a specific one. I can preserve the order of the data after running a List Report, but I have been unable to run a filter (or whatever the process is) to get the data into the correct order before a Report step.

If anyone has any thoughts or suggestions, I’d appreciate them.
-Steven
2 REPLIES 2
Doc_Duke
Rhodochrosite | Level 12
Add a column that represents sort order and then do the appropriate transformations/data entry to allow you to do an ascending or descending sort.

Depending on the procedures that you are using, you may be able to do this with a format (some procedures will display in the formatted order).
RichardH_sas
SAS Employee
All of Doc's suggestions are right on the money. The lazy person's solution would be to recode the column so the values are:

1 - X
2 - Z
3 - Y
4 - W

If this is acceptable, it's definitely a simple solution (and one I've used many, many times). If you MUST have the values stay X, Y, W, Z; I would recommend Doc's approach of recording the values similar to above (1 - X, 2 - Z,...) and creating a custom format that causes 1 - X to display as X. If you then order by the Unformatted values, you're good to go. As Doc mentions, this trick will not necessarily works in every possible situation, though it works in most of them.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 2 replies
  • 1114 views
  • 0 likes
  • 3 in conversation