Help using Base SAS procedures

Prior and Post

Reply
Super Contributor
Posts: 1,041

Prior and Post

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) ;

PROC Star
Posts: 7,485

Re: Prior and Post

Posted in reply to robertrao

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.

Super Contributor
Posts: 1,041

Re: Prior and Post

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)

Super User
Posts: 19,833

Re: Prior and Post

Posted in reply to robertrao

Is time a factor for these date time comparisons?

Super Contributor
Posts: 1,041

Re: Prior and Post

no

PROC Star
Posts: 7,485

Re: Prior and Post

Posted in reply to robertrao

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.

Ask a Question
Discussion stats
  • 5 replies
  • 223 views
  • 0 likes
  • 3 in conversation