Date: Mon, 8 Dec 2003 11:54:16 -0500
Reply-To: Jay Weedon <jweedon@EARTHLINK.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jay Weedon <jweedon@EARTHLINK.NET>
Organization: http://extra.newsguy.com
Subject: Re: how to define a new rank ?
Content-Type: text/plain; charset=us-ascii
On Mon, 08 Dec 2003 11:23:26 -0500, Nabil Benabbou
<benabbou@uottawa.ca> wrote:
>Hello everyone
>
>I want to create a new variable `r' in the following data (here is an
>example)
>
>Data data1;
>input x y;
>cards;
>1 40
>1 30
>1 30
>2 10
>2 10
>3 20
>3 10
>3 30
>; run;
>
>The treatment would be
>
>proc sort data=data1; by x;
>
>the rank would be defined by the second variable y
>
>The output will be :
>
>x y r
>1 40 1
>1 30 2
>1 30 2
>2 10 1
>2 10 1
>3 20 2
>3 10 3
>3 30 1
>
Here's one method:
proc sort data=data1; by x descending y; run;
data data3;
set data1;
by x descending y;
lasty=lag1(y); drop lasty;
if first.x then rank=1;
else if y<lasty then rank+1;
run;
Or you could try proc rank with a by statement.
JW
|