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

Hello

Let's say that I have a  data set (summary report) and I want to re-order the rows.

The issue is that I don't want to order it by descending criteria and not by ascending criteria.

I want to to order it by order that I want to define in advance.

I want that order of rows will be by "team" :bcbfb, jdjfj,asddd

and within each team by Profit(from high value to low value).

Data Report;
input team $ sub_team $ Profit;
cards;
asddd a 10 
asddd b 30
asddd c 20 jdjfj a 40
jdjfj b 50
jdjfj c 15 bcbfb a 35
bcbfb b 46
bcbfb c 90
;
run;
/*The required order of rows is bcbfb jdjfj asddd */

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Create a team order variable and sort by that. Use PROC FORMAT to assign the order:

proc format;
  value $team_order
  bcbfb = '1'
  jdjfj    = '2'
  asddd = '3'
  ;
run;

data want;
  set have;
  team_order = put(team, $team_order.);
run;

proc sort data = want;
  by team_order;
run;

View solution in original post

1 REPLY 1
SASKiwi
PROC Star

Create a team order variable and sort by that. Use PROC FORMAT to assign the order:

proc format;
  value $team_order
  bcbfb = '1'
  jdjfj    = '2'
  asddd = '3'
  ;
run;

data want;
  set have;
  team_order = put(team, $team_order.);
run;

proc sort data = want;
  by team_order;
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—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
  • 1 reply
  • 746 views
  • 0 likes
  • 2 in conversation