Help using Base SAS procedures

Help converting ROW_NUMBER() OVER (PARTITION BY

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Help converting ROW_NUMBER() OVER (PARTITION BY

Could someone please help me to understand how I could convert the following into PROC SORT then PROC RANK?

 

ROW_NUMBER() OVER (PARTITION BY UNIQUE_ID ORDER BY mem_no desc, drug_id desc, RX_FILL_DT ASC) AS RANK

 

FYI, formats:

alphanumeric:

UNIQUE_ID 

DRUG_ID

 

date:

RX_FILL_DT

 

numeric:

MEM_NO

 

SAS EG v. 7.13


Accepted Solutions
Solution
‎12-04-2017 01:48 PM
Super User
Posts: 23,754

Re: Help converting ROW_NUMBER() OVER (PARTITION BY

if first.rx_fill_dt_asc ...

I think auto correct deleted the period, there should be a period between. 

 

FIRST. identifies the first in that particular variable group.

View solution in original post


All Replies
Super User
Posts: 23,754

Re: Help converting ROW_NUMBER() OVER (PARTITION BY

Posted in reply to vanpeltm1785

PROC SORT data=have;

by  mem_no desc descending drug_id  RX_FILL_DT ASC;

run;

 

proc rank data=have;

by < ... >;

 

VAR ...;

run;

 

I'm not sure what variable is being ranked here or if it's just creating a count variable per group. I suspect the latter which would be easier in a data step.

 

data want;
set have;

by <   >;

if first rx_fill_dt_asc then count=0;
count+1;
run;
New Contributor
Posts: 4

Re: Help converting ROW_NUMBER() OVER (PARTITION BY

I get this error:

if first rx_fill_dt_asc then count=0;
______________
388
76
ERROR 388-185: Expecting an arithmetic operator.

Solution
‎12-04-2017 01:48 PM
Super User
Posts: 23,754

Re: Help converting ROW_NUMBER() OVER (PARTITION BY

if first.rx_fill_dt_asc ...

I think auto correct deleted the period, there should be a period between. 

 

FIRST. identifies the first in that particular variable group.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 2998 views
  • 1 like
  • 2 in conversation