I have a question about using PROC RANK function.
I usually use SQL in the company however I need to edit SAS query as well.
Problem :
I want to express below SQL query in SAS
RANK() OVER (PARTITION BY GROUP_NAME ORDER BY START_DATE DESC) AS SEQ
I tried below query but I need to make a rank based on START_DATE order by descending.
If anybody can give the answer of it, please let me know.
PROC RANK DATA = WORK.DATA_EXTRACTION1 OUT = WORK.DATA_EXTRACTION2; BY GROUP_NAME; VAR START_DATE; RANKS SEQ; RUN;
Sadly window functions are not supported yet in SAS.
Have you tried the descending option for proc rank?
> It doesn't work well.
Please describe the issue; "does not work" is meaningless when looking for help. This option works as described.
You will have to add a sort step to get the required order, as the DESCENDING option only controls how the ranks are assigned, but not how the output is sorted.
proc sort
data=sashelp.class
out=class
;
by sex;
run;
proc rank
data=class
out=want
ties=low
;
by sex;
var age;
ranks age_rank;
run;
proc sort data=want;
by sex descending age_rank;
run;
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!
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.