BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Q1983
Lapis Lazuli | Level 10

data have1;

input ln $ setup_dt Date9. ;

format setup_dt mmddyy10.;

datalines;

 

12000 29Jul2019

12000 30Jul2019

12000 30Jul2019

12000 31Jul2019

12500 31Aug2019

15600 1Aug2019

15700 2Aug2019

;run;

data want;

set have1;

by ln ;

if first.ln then group_id+1;

run;

Output

ln setup_dt group_id
12000 07/29/2019 1
12000 07/30/2019 1
12000 07/30/2019 1
12000 07/31/2019 1
12500 08/31/2019 2
15600 08/01/2019 3
15700 08/02/2019 4
     
Desired as follows
     
ln setup_dt group_id
12000 07/29/2019 1
12000 07/30/2019 2
12000 07/30/2019 2
12000 07/31/2019 3
12500 08/31/2019 1
15600 08/01/2019 1
15700 08/02/2019 1

The desire is that when the same ln shows a new setup_dt, it increments from 1 to 2 or 3 etc depending on the number of dates.  It then should reset to 1 when the ln changes

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data want;
set have1;
by ln setup_dt;
if first.ln then group_id=1;
else if first.setup_dt then group_id+1;
run;

View solution in original post

1 REPLY 1
novinosrin
Tourmaline | Level 20
data want;
set have1;
by ln setup_dt;
if first.ln then group_id=1;
else if first.setup_dt then group_id+1;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 563 views
  • 2 likes
  • 2 in conversation