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

Hello

In real life I have a data set in Long structure where each customer has multiple rows.

In each row there is information on explanatory variables from regression model.

I want to order the rows in the way that for each customer there will be the following order or rows

Wealth
Cycle
Educ
Age
Inter

 

What is the way to do it please?

The order is not by alphabetical order  (it is by user defined criteria)

 

Data have;
input category $;
cards;
Inter
Age
Educ
Wealth
Cycle
;
Run;


Data wanted;
input category $;
cards;
Wealth
Cycle
Educ
Age
Inter
;
Run;
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

proc sql;
   create table want as
   select category from have
   order by whichc(category, 'Wealth', 
                             'Cycle',
                             'Educ',
                             'Age',
                             'Inter');
quit;

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

I want to order the rows in the way that for each customer there will be the following order or rows

Wealth
Cycle
Educ
Age
Inter


Create a new variable which is one when the value is "Wealth" and 2 when the value is "Cycle" and so on, then sort by this new variable.

 

 

--
Paige Miller
Ronein
Meteorite | Level 14
This is the best solution and works well always . Thank you
PeterClemmensen
Tourmaline | Level 20

Try this

 

proc sql;
   create table want as
   select category from have
   order by whichc(category, 'Wealth', 
                             'Cycle',
                             'Educ',
                             'Age',
                             'Inter');
quit;
PeterClemmensen
Tourmaline | Level 20

@Ronein if this works for you, please mark it as the solution. 

Ronein
Meteorite | Level 14
It is a good solution but in real world I need to sort by customer ID and then by user defined category order and here it is not working well

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 924 views
  • 4 likes
  • 3 in conversation