BookmarkSubscribeRSS Feed
znhnm
Quartz | Level 8

I had a char variable in my dataset where I changed it to be numeric. When I sort the dataset by this new numeric variable, the sort is not quite right. What I mean is that, to some point, the sort is correct but then, it has a record that does not fit the sort order than another "correct" sort start.

For example:

20
21
22
23
24
25
10
11
12
13

What ould cause this and how to solve this?

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Can you post the code or some come that resembles your problem?

 

Are you sure your sort only by the numeric variable? And are you sure that the variable is actually numeric? Is the data formated?

ballardw
Super User

Very likely something related to your data.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.

SASKiwi
PROC Star

Run this program on your dataset and check the sort information:

proc contents data = MyDataset;
run;

It should look similar to this:

SASKiwi_0-1670962887026.png

If your results don't show any sort information then your SORT didn't work.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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