Help using Base SAS procedures

Adding dates between incident-dates

Reply
Contributor
Posts: 62

Adding dates between incident-dates

All,

I've got a table with multiple variables, an incident date and id's which can occur more than once. The incident date changes every time an incident occur. Like:

ID | Incident txt || Incident Date
1 A 01-01-2008
1 A 05-03-2008
1 B 08-03-2008
2 B 02-02-2008
2 F 03-04-2008
3 A 05-02-2008

Before, I had an table where on 1 row I've had an start and an end date, and with the statement: "do date = start_date to end_date by 1", it was extremeley simple to create a table with all the dates since between incidents for every ID (and later on, filling in the missing values which wasn't really a problem).

But now, when the 'end' date is on the following row, I have no idea how to create a table with all the dates between incidents per ID!

Anyone have any idea? Thanks in advance!
Frequent Contributor
Frequent Contributor
Posts: 76

Re: Adding dates between incident-dates

You could use the lag function to generate a start and end data variable.

Something like this might work-- but I'm not sure what you want to do with single incident (like 3 A 05-02-2008)

Data a;
input ID Incident txt startDate;
cards;
1 A 01-01-2008
1 A 05-03-2008
1 B 08-03-2008
2 B 02-02-2008
2 F 03-04-2008
3 A 05-02-2008
;
run;

proc sort; by id startdate;

data b;
set a;
by id;

enddate=lag(startdate);

if first.id then delete; /* or if first.id then enddate = .;
run;
Ask a Question
Discussion stats
  • 1 reply
  • 91 views
  • 0 likes
  • 2 in conversation