BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
shasank
Quartz | Level 8

Hi SAS Community,

 

 

I need in your help in the below regard.

 

I have a data set like this:-

IDStartDate
19-May-12
110-May-12
110-May-12
130-May-12
130-Jun-12
  
217-May-12
230-May-12
231-May-12
226-Jun-12
  
326-Jun-12
329-Jun-12
327-Jul-12
325-Aug-12

 

 


And want an output like this:- 

IDStartDateLine
19-May-121
110-May-121
110-May-121
130-May-122
   
217-May-121
230-May-121
231-May-121
226-Jun-122
   
326-Jun-121
329-Jun-121
327-Jul-122
325-Aug-123

 

Basically, The logic is that if there is a gap of more than 20 between the dates by ID then the Line variable should increase by 1.

 

Thank you for your time and I appreciate your help.

 

Regards,

SC.

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data have;
input ID StartDate :date7.;
format startdate date7.;
datalines;
1 9-May-12
1 10-May-12
1 10-May-12
1 30-May-12
2 17-May-12
2 30-May-12
2 31-May-12
2 26-Jun-12
3 26-Jun-12
3 29-Jun-12
3 27-Jul-12
3 25-Aug-12
;

data want;
set have;
by id;
k=lag(startdate);
if first.id then line=1;
else if intck('day',k,startdate)>=20 then line+1;
drop k;
run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

data have;
input ID StartDate :date7.;
format startdate date7.;
datalines;
1 9-May-12
1 10-May-12
1 10-May-12
1 30-May-12
2 17-May-12
2 30-May-12
2 31-May-12
2 26-Jun-12
3 26-Jun-12
3 29-Jun-12
3 27-Jul-12
3 25-Aug-12
;

data want;
set have;
by id;
k=lag(startdate);
if first.id then line=1;
else if intck('day',k,startdate)>=20 then line+1;
drop k;
run;

shasank
Quartz | Level 8
You are of great help. Thank you very much.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 677 views
  • 0 likes
  • 2 in conversation