Hello, I have a dataset with variable part
data test;
input part $16.;
datalines;
MD-III_3BQ
MD-II_3BQ
MD-I_3BQ
MD_3BQ
SG-III_5AP
SG-II_5AP
SG-I_5AP
SG_5AP
;
run;
The output I want is the follows:
MD_3BQ
MD-I_3BQ
MD-II_3BQ
MD-III_3BQ
SG_5AP
SG-I_5AP
SG-II_5AP
SG-III_5AP
when I use proc sort, I did not get what I want? Could anyone help me? Thanks!
proc sort sortseq=linguistic(numeric_collation=on);
by part;
run;
Thank you Data_null_. That is what I want!
I can't see a logical way of sorting that data, my advice would be to create either a numeric order variable, or create a format (some people like formats for this type of thing, me I avoid catalogs as much as possible). So either:
data test;
set test;
select (part);
when ("MD-III_3BQ") seq=...;
when...
end;
run;
Or:
proc format;
value $prt
"MD-III_3BQ"=...
"MD-II_3BQ"=...
...
;
run;
data test;
set test;
ord=input(part,$prt.);
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.