DATA Step, Macro, Functions and more

Create rank from a flag

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Create rank from a flag

[ Edited ]

Hi Everyone,

 

Could you please help me to code the below logic.

 

I have a flag variable in my data set and I want to create a Rank variable in the following way.

 

PS: I'm using SAS 9.4.

 

flag Rank
0 1
1 2
1 2
1 2
0 3
1 4
1 4
0 5
1 6
1 6
1 6

 

Thanks a lot in Advance.


Accepted Solutions
Solution
‎11-29-2016 04:14 AM
Super User
Posts: 6,955

Re: SAS Rows

data want;
set have;
by flag notsorted;
retain rank 0;
if first.flag then rank + 1;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎11-29-2016 04:14 AM
Super User
Posts: 6,955

Re: SAS Rows

data want;
set have;
by flag notsorted;
retain rank 0;
if first.flag then rank + 1;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 12

Re: SAS Rows

This is helpful.

 

Thanks..)

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 176 views
  • 2 likes
  • 2 in conversation