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?
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 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 |
There is an option for that.
proc sort sortseq=LINGUISTIC(NUMERIC_COLLATION=ON);
by var;
run;
Much thanks guru @data_null__ as always.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.