DATA Step, Macro, Functions and more

How to sort the data with I II III ?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 102
Accepted Solution

How to sort the data with I II III ?

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!


Accepted Solutions
Solution
‎11-29-2017 10:41 AM
Respected Advisor
Posts: 3,852

Re: How to sort the data with I II III ?

[ Edited ]

 

 

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

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

 

View solution in original post


All Replies
Solution
‎11-29-2017 10:41 AM
Respected Advisor
Posts: 3,852

Re: How to sort the data with I II III ?

[ Edited ]

 

 

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

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

 

Frequent Contributor
Posts: 102

Re: How to sort the data with I II III ?

Posted in reply to data_null__

Thank you Data_null_. That is what I want!

Super User
Super User
Posts: 9,599

Re: How to sort the data with I II III ?

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;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 178 views
  • 3 likes
  • 3 in conversation