BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Rakeon
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@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.

View solution in original post

2 REPLIES 2
Reeza
Super User

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;
Patrick
Opal | Level 21

@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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1026 views
  • 4 likes
  • 3 in conversation