BookmarkSubscribeRSS Feed
robertrao
Quartz | Level 8

Is my interpretation correct

if first date is 20th.could someone explain to me with example

/*date is WITHIN 5 days prior to the first_date*/

if date ge (first_date - 60*60*24*5)

/*date is WITHIN 5 days post to the first_date*/

    if date le (first_date + 60*60*24*5) ;

5 REPLIES 5
art297
Opal | Level 21

If first_date is a datetime field, the comparisons are just adding or subtracting the number of seconds elapsed before or after a given date.  However, neither is accounting for WITHIN a given time period as such a comparison would require three dates to be compared.

robertrao
Quartz | Level 8

first_date is a datetime field. and date is also date time field

i have two datetimess: date and first_date

i want to see if date is within +/- 5 days of first_date

and the below is for +5 or -5????

if date ge (first_date - 60*60*24*5)

Reeza
Super User

Is time a factor for these date time comparisons?

robertrao
Quartz | Level 8

no

art297
Opal | Level 21

Robert,

Be careful how you answer Fareeza'a question.  It isn't a factor if your times are all zero but, if they do represent actual times, you could be misclassifying the differences.  The following does consider time to be relevant:

data have;

  informat date first_date datetime21.;

  format date first_date datetime21.;

  informat test_date date9.;

  format test_date date9.;

  input test_date span;

  first_date=dhms(test_date,0,0,0);

  date=dhms(test_date+span,0,0,0);

  /*date is WITHIN 5 days prior to the first_date*/

  prior=-5*60*60*24 le date-first_date le 0;

  /*date is WITHIN 5 days post to the first_date*/

  post=0 le date-first_date le 5*60*60*24;

  cards;

03DEC2013 4

03DEC2013 6

03DEC2013 -4

03DEC2013 -6

;

If time really isn't relevant, and aren't all represented with zeros, than I'd suggest changing the formulas to compare the dateparts of the two fields and not adjusted for seconds.

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
  • 5 replies
  • 1536 views
  • 0 likes
  • 3 in conversation