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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 887 views
  • 0 likes
  • 2 in conversation