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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.