BookmarkSubscribeRSS Feed
Wouter
Obsidian | Level 7
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!
1 REPLY 1
LAP
Quartz | Level 8 LAP
Quartz | Level 8
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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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