BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
daisy6
Quartz | Level 8

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!

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

 

 

proc sort sortseq=linguistic(numeric_collation=on);
   by part;
   run;

2017-11-29_9-35-57.png

 

View solution in original post

3 REPLIES 3
data_null__
Jade | Level 19

 

 

proc sort sortseq=linguistic(numeric_collation=on);
   by part;
   run;

2017-11-29_9-35-57.png

 

daisy6
Quartz | Level 8

Thank you Data_null_. That is what I want!

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 768 views
  • 3 likes
  • 3 in conversation