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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.