- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.