BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jacksonan123
Lapis Lazuli | Level 10

I have the following data under the variable name folder.

Folder

test1.nm7

test100.nm7

test1001.nm7

test2.nm7

test3.nm7

I would like to sort this data to give me the test in the following numerical order.

Folder

test1.nm7

test2.nm7

test3.nm7

test100.nm7

test1001.nm7

Can someone tell me how to do this?

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data have;
input var :$15.;
cards; 
test1.nm7

test100.nm7

test1001.nm7

test2.nm7

test3.nm7
;

proc sql;
 create table want as
 select *
 from have
 order by input(compress(scan(var,1,'.'),,'kd'),32.);
quit;

 The idea is to extract and sort the numerical part in the pattern. 

var
test1.nm7
test2.nm7
test3.nm7
test100.nm7
test1001.nm7

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

data have;
input var :$15.;
cards; 
test1.nm7

test100.nm7

test1001.nm7

test2.nm7

test3.nm7
;

proc sql;
 create table want as
 select *
 from have
 order by input(compress(scan(var,1,'.'),,'kd'),32.);
quit;

 The idea is to extract and sort the numerical part in the pattern. 

var
test1.nm7
test2.nm7
test3.nm7
test100.nm7
test1001.nm7
data_null__
Jade | Level 19

There is an option for that.

 

proc sort sortseq=LINGUISTIC(NUMERIC_COLLATION=ON);
   by var;
   run;

Capture.PNG

novinosrin
Tourmaline | Level 20

Much thanks guru @data_null__  as always. 

jacksonan123
Lapis Lazuli | Level 10
I will give it a try later but the prior post resolved the issue.
Ksharp
Super User
Could be simpler as :


select *
from have
order by input(scan(var,1,,'kd'),32.);
jacksonan123
Lapis Lazuli | Level 10
It does work I had put in something wrong. I will accept it as a solution.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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