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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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