BookmarkSubscribeRSS Feed
rakeshvvv
Quartz | Level 8

I have dataset with three varaibles id startdate enddate. Dates are numerical sas formats.

I would like to pull out the records for id where the difference between the two succesive START dates is more then 28 days.

example:

ID    STARTDATE ENDDATE

001   19583      19604

001   19589      19609

001   19600      19610

001   19628      19638

001   19480      19520

1 REPLY 1
Kurt_Bremser
Super User

This looks like an appliaction for a dow loop:

data want (keep=id1 st1 enddate rename=(id1=id st1=startdate));

format id1 st1 enddate; /* just to keep the vars in order */

do until ((startdate - lastdate >= 28) or finish);

  lastdate = startdate;

  set have end=finish;

  by id;

  if first.id then lastdate = startdate;

end;

if startdate - lastdate >= 28

then do;

  do until (lastdate = st1 and id = id1); /* read to the first record */

    set have (rename=(id=id1 startdate=st1));

  end;

  output;

  do until (startdate = st1 and id = id1); /* read to the second record */

    set have (rename=(id=id1 startdate=st1));

  end;

  output;

end;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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