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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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