BookmarkSubscribeRSS Feed
KaiBasch
Calcite | Level 5

Dear experts,

 

I'm trying to sort a column which has records like 'AA0276', 'A2B5Q', 'AB8ER', ...

 

After I sort the data, I'm running a data step and use the sorted column in a by statement.

 

The data step returns a ERROR which indicates that the by variable couldn't sorted for the values like 'AA0276' which have two consequent character values.

 

ERROR: Error: BY variables are not properly sorted.

 

How can I fix this problem?

 

 

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

If SAS says that your data is not sorted by that variable, it is not.

 

Post some sample data and your code.

KaiBasch
Calcite | Level 5

Yes, that's obvious from the log but if you read my 2nd sentence you would see that I've sorted the data (using Proc Sort), it is sorted.

Astounding
PROC Star

You'll have to post the log.  I can think of several possibilities, but I'm not about to explain them all in detail just in case one of them matches the situation you are encountering.

Reeza
Super User

@KaiBasch wrote:

Yes, that's obvious from the log but if you read my 2nd sentence you would see that I've sorted the data (using Proc Sort), it is sorted.


Post your full code and log. Obviously SAS doesn't think the data set is sorted for some reason.

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