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

Hello,

 

Can anyone help me to re-order my value in this dataset. I want my "Q1,Q3" before "min,Max" value in variable  _SUBVARLBL_.  

 

 

re-order.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data _temp;
set have;

if compress(_subvarlbl_) = 'n' then order_var=1;
else if compress(_subvarlbl_) = 'Mean' then order_var=2;
.....

else order_var = 0;

run;

proc sort data=_temp;
by _varval_ order_var;
run;

Here's the idea, you can code the remaining groups as needed. I used COMPRESS() on the strings because it appears you have leading spaces and this will remove them.  Be careful with COMPRESS() and text with hyphens or comma's though.

 


@unnati wrote:

Hello,

 

Can anyone help me to re-order my value in this dataset. I want my "Q1,Q3" before "min,Max" value in variable  _SUBVARLBL_.  

 

 

re-order.PNG


 

View solution in original post

3 REPLIES 3
Reeza
Super User
You'll have to add some variables to control the ordering.
Map N=1, mean=2, SD=3, ... Q1,Q3 = 5, min/max=6 and anything else 0.

Then sort by _VARVAL_ and the new variable created with the numbers.
unnati
Obsidian | Level 7

can you provide me answer with code Please ??

 

Thank you

Reeza
Super User
data _temp;
set have;

if compress(_subvarlbl_) = 'n' then order_var=1;
else if compress(_subvarlbl_) = 'Mean' then order_var=2;
.....

else order_var = 0;

run;

proc sort data=_temp;
by _varval_ order_var;
run;

Here's the idea, you can code the remaining groups as needed. I used COMPRESS() on the strings because it appears you have leading spaces and this will remove them.  Be careful with COMPRESS() and text with hyphens or comma's though.

 


@unnati wrote:

Hello,

 

Can anyone help me to re-order my value in this dataset. I want my "Q1,Q3" before "min,Max" value in variable  _SUBVARLBL_.  

 

 

re-order.PNG


 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 2405 views
  • 0 likes
  • 2 in conversation