BookmarkSubscribeRSS Feed
chinna0369
Pyrite | Level 9

Hi all, 

 

I would like assign a sequential order for my data. I have id dose variables. like below

ID    DOSE

1      20

1      20

1      17

1      17

1      15

1      15

 

I want like below 

 

ID  DOSE SEQ

1   20        0

1   20        0

1  17         1

1  17         1

1  15         2

1  15         2

 

Can you please help me with this.

 

Thanks,

Adi

 

4 REPLIES 4
Astounding
PROC Star

One way:

data want;
   set have;
   by id dose notsorted;
   if first.id then seq=0;
   else if first.dose then seq + 1;
run;
chinna0369
Pyrite | Level 9
No, this is not working. Thanks!
Astounding
PROC Star

I don't believe you.  Prove me wrong by posting the log from your job where it doesn't work.

Kurt_Bremser
Super User

@chinna0369 wrote:
No, this is not working. Thanks!

Don't be silly.

data have;
input id dose;
datalines;
1      20
1      20
1      17
1      17
1      15
1      15
;

data want;
   set have;
   by id dose notsorted;
   if first.id then seq=0;
   else if first.dose then seq + 1;
run;

proc print data=want noobs;
run;

Result:

id	dose	seq
1	20	0
1	20	0
1	17	1
1	17	1
1	15	2
1	15	2

EXACTLY what you want.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 730 views
  • 0 likes
  • 3 in conversation