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;
Try this
proc sql;
create table want as
select category from have
order by whichc(category, 'Wealth',
'Cycle',
'Educ',
'Age',
'Inter');
quit;
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.
Try this
proc sql;
create table want as
select category from have
order by whichc(category, 'Wealth',
'Cycle',
'Educ',
'Age',
'Inter');
quit;
@Ronein if this works for you, please mark it as the solution.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.