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;

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
  • 1 reply
  • 301 views
  • 2 likes
  • 2 in conversation