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

I have a dataset with three variables (var1, var2, var3). How can I go about indexing the dataset by var1, but making sure that var2 is also sorted in descending order?

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
djbateman
Lapis Lazuli | Level 10

I just had thought.  Your data may not necessarily have to be sorted by var1 before it is indexed.  I just assumed that you would index it based on a certain order.  If your data is already in the order that you want, then you can skip the first sort procedure.

View solution in original post

3 REPLIES 3
djbateman
Lapis Lazuli | Level 10

What do you mean by indexing by var1?  Do you mean to know which observation is observation #1, #2, etc. but still sorting on var2?  In other words, var2 will be in order, but the index for var1 will not necessarily be in any order?  If that is what you mean, then try this little snippet:

proc sort data=dsn;

      by var1;

run;

data dsn;

      set dsn;

   index=_n_;

run;

proc sort data=dsn;

      by descending var2;

run;

djbateman
Lapis Lazuli | Level 10

I just had thought.  Your data may not necessarily have to be sorted by var1 before it is indexed.  I just assumed that you would index it based on a certain order.  If your data is already in the order that you want, then you can skip the first sort procedure.

maroulator
Obsidian | Level 7

Your answer is exactly what I needed.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 693 views
  • 0 likes
  • 2 in conversation