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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 380 views
  • 0 likes
  • 4 in conversation