DATA Step, Macro, Functions and more

sequence

Accepted Solution Solved
Reply
Contributor
Posts: 54
Accepted Solution

sequence

[ Edited ]

Hi 

 

I would like to apply basevalue .like if id is 13 then 1,if id is 14 then 2 but in my code I am getting basevalue increamented for same id.Can anyone guide with the code.

(if first.id then basevalue=1;

basevalue+1;

 

dataset I want is like this

ID BASEVALUE
13 1
13 1
13 1
14 2
14 2
15 3
15 3
15 3
16 4


Accepted Solutions
Solution
‎03-28-2018 03:02 PM
PROC Star
Posts: 1,592

Re: sequence

data have;
input ID ;
datalines;
13 1
13 1
13 1
14 2
14 2
15 3
15 3
15 3
16 4
;

data want;
set have;
by id;
if first.id then BASEVALUE+1;
run;

/*or*/

data want;
set have;
by id;
if lag(id) ne id then BASEVALUE+1;
run;

View solution in original post


All Replies
Super User
Posts: 6,637

Re: sequence

You're close ... combine your two statements:

 

if first.id then basevalue + 1;

Solution
‎03-28-2018 03:02 PM
PROC Star
Posts: 1,592

Re: sequence

data have;
input ID ;
datalines;
13 1
13 1
13 1
14 2
14 2
15 3
15 3
15 3
16 4
;

data want;
set have;
by id;
if first.id then BASEVALUE+1;
run;

/*or*/

data want;
set have;
by id;
if lag(id) ne id then BASEVALUE+1;
run;
Contributor
Posts: 54

Re: sequence

Posted in reply to novinosrin

Thank you Smiley Happy

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 113 views
  • 0 likes
  • 3 in conversation