Hi,
I need to convert this Oracle Code in SAS :
row_number() over (partition by Var1, Var2, Var3
order by Var 4, Var5, Var6)
I'm trying with proc rank, but it requires just one variable in rank parameter.
I would like to know if is there any chance to implement it with proc rank.
Thanks
@Rakeon wrote:
Hi,
I need to convert this Oracle Code in SAS :
row_number() over (partition by Var1, Var2, Var3
order by Var 4, Var5, Var6)
I believe below should return the same result.
proc sort data=have out=want;
by Var1 Var2 Var3 Var4 Var5 Var6;
run;
data want;
set want;
by Var1 Var2 Var3;
if first.var3 then row_num=1;
else row_num+1;
run;
NB: In your subject line you mention Proc Rank BUT in the Oracle SQL code you're using row_number()
If you need anything that can deal with ties (multiple rows with identical values for variables var1 to var6) then you would need to use Oracle functions RANK() or RANK_DENSE() ...and in doing so the SAS code would also need to look a bit differently.
No, but data step + proc sort would probably work.
Not sure this is quite right, but the idea is there
data want;
set have;
by var1 var2 var3;
if first.var then count=0;
else count+1;
run;
proc sort data=want;
by var4 var5 var6;
run;
@Rakeon wrote:
Hi,
I need to convert this Oracle Code in SAS :
row_number() over (partition by Var1, Var2, Var3
order by Var 4, Var5, Var6)
I believe below should return the same result.
proc sort data=have out=want;
by Var1 Var2 Var3 Var4 Var5 Var6;
run;
data want;
set want;
by Var1 Var2 Var3;
if first.var3 then row_num=1;
else row_num+1;
run;
NB: In your subject line you mention Proc Rank BUT in the Oracle SQL code you're using row_number()
If you need anything that can deal with ties (multiple rows with identical values for variables var1 to var6) then you would need to use Oracle functions RANK() or RANK_DENSE() ...and in doing so the SAS code would also need to look a bit differently.
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.