Help using Base SAS procedures

sorting varaible

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 145
Accepted Solution

sorting varaible

I have character variable with numerical values...While sorting I am getting the following way.....is there way that i can get as 1,2,3,4,5,6,,7,8 instead of 1,1,10,10,11,11

100010002    1

100010002    1

100010002    10

100010002    10

100010002    11

100010002    11

100010002    11

100010002    12

100010002    12

100010002    13

100010002    13

100010002    2

100010002    2

100010002    3

100010002    4

100010002    5

100010002    6

100010002    7

100010002    8

100010002    8


Accepted Solutions
Solution
‎11-24-2014 11:37 AM
Respected Advisor
Posts: 3,156

Re: sorting varaible

Posted in reply to rakeshvvv

proc sort data=have SORTSEQ=LINGUISTIC;

by x; run;

View solution in original post


All Replies
Solution
‎11-24-2014 11:37 AM
Respected Advisor
Posts: 3,156

Re: sorting varaible

Posted in reply to rakeshvvv

proc sort data=have SORTSEQ=LINGUISTIC;

by x; run;

Respected Advisor
Posts: 3,799

Re: sorting varaible

Do you need numeric_collation sub-option?

Frequent Contributor
Posts: 145

Re: sorting varaible

Posted in reply to data_null__

I have charceter variable but it has only numeric values........so i would like do sorting the way we do it for numeric but for character variable......

Respected Advisor
Posts: 3,156

Re: sorting varaible

Posted in reply to data_null__

Yes, DN, you are right, so for Proc Sort:

proc sort data=have SORTSEQ=LINGUISTIC (numeric_collation=on)

by x; run;

Or if using Proc SQL:

proc sql;

create table want (drop=skey) as

  select *, sortkey(x,'','','','NUMERIC','') as skey

  from have

order by skey;

quit;

🔒 This topic is solved and locked.

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

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