BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mistervv
Calcite | Level 5

Hello, first time user for a couple of weeks now and have an issue with the SORT function.

When I sort by var (which is numeric, 1 until 13) I get:

1

10

11

12

13

2

3

4

5

6

etc.

In my other similar database I didn't have this issue, strange. Anyone knows how to fix this? Here's the basic code:

Proc sort data = data out = sorteddata;

  by variable;

RUN;

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

It doesn't look like a numeric I am afraid.  It looks like that variable is a character, hence it Is sorting textually.

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

It doesn't look like a numeric I am afraid.  It looks like that variable is a character, hence it Is sorting textually.

Mistervv
Calcite | Level 5

I just ran a PROC CONTENTS and you're right. I find it strange it switched to Char, since it was Num in my main database, but thanks!

Ksharp
Super User

There is an option in proc sort can do that ,you need to check documentation . another way is sql.

Here is :

NUMERIC_COLLATION=on

Message was edited by: xia keshan

Mistervv
Calcite | Level 5

Where do I put this in my code? Just out of curiosity. I just changed my variable to numeric by multiplying it by 1 now. Thanks.

scmebu
SAS Employee
data test;
 length v $ 3;
 input v;
 cards;
1
10
11
12
13
2
3
4
5
6
;
run;

proc sort data=test sortseq=linguistic(numeric_collation=on);
by v;
run;

proc print data=test;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 3581 views
  • 6 likes
  • 4 in conversation