Help using Base SAS procedures

Proc sort (ascending) takes 11 12 13, etc. before 2

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Proc sort (ascending) takes 11 12 13, etc. before 2

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.


Accepted Solutions
Solution
‎07-29-2014 10:21 AM
Super User
Super User
Posts: 7,401

Re: Proc sort (ascending) takes 11 12 13, etc. before 2

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


All Replies
Solution
‎07-29-2014 10:21 AM
Super User
Super User
Posts: 7,401

Re: Proc sort (ascending) takes 11 12 13, etc. before 2

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

Occasional Contributor
Posts: 5

Re: Proc sort (ascending) takes 11 12 13, etc. before 2

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!

Super User
Posts: 9,681

Re: Proc sort (ascending) takes 11 12 13, etc. before 2

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

Occasional Contributor
Posts: 5

Re: Proc sort (ascending) takes 11 12 13, etc. before 2

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.

SAS Employee
Posts: 17

Re: Proc sort (ascending) takes 11 12 13, etc. before 2

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;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 475 views
  • 6 likes
  • 4 in conversation