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.
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.
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;
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.
Your answer is exactly what I needed.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.