Edit check for database validation: How to make sure one variable occurred 4hrs before a different one?

Reply
Occasional Contributor
Posts: 9

Edit check for database validation: How to make sure one variable occurred 4hrs before a different one?

Hello everyone,

I am trying to write an edit check that ensures that the value of one variable occurred at least 4 hours prior to a different variable value, and did not occur at all after a different variable. Here are the variables I have and what they mean:

subject   =     Subject

instm     =      Start Time of Insulin

baslintm =      Time of Baseline Fingerstick

dischatm =     Time of Discharge Fingerstick

I want the edit check to call out whenever the start time of insulin occurred at a time that was not at least 4 hrs prior to the time of the baseline fingerstick reading. I also want to ensure that the start time of insulin did not occur at all after the time of  the discharge fingerstick. I am using a Proc SQL statement and I'm having trouble writing the "where" clause in a way that would do this. I am a SAS newbie and dont really know syntax well so any help would be appreciated.

Here is the code I have now:

proc sort data=tbl_insulin_list; by subject; run;

  proc sort data=tblIn_Clinic_Day; by subject; run;

  data InsulinTime;

  merge tbl_insulin_list tblIn_Clinic_Day;

  by subject;

  run;

%let data67=insulin_time;

  proc sql;

   create table &data67 as

    select subject label='Subject|Number'

   ,instm label='Start Time of Insulin'

   ,baslintm label='Time of Baseline Fingerstick'format=time5.

   ,dischatm label='Time of Discharge Fingerstick'format=time5.

     from InsulinTime

  where instm=. | (instm >= (baslintm - (04:00)))| instm>= dischatm

  order subject;

  quit;

Thank you!

-Tyler

Super User
Posts: 19,833

Re: Edit check for database validation: How to make sure one variable occurred 4hrs before a different one?

Posted in reply to tkallday33

The or operator depends on your OS, so make sure that | is valid for yours.

SAS time is measured in seconds so you can subtract the two and check that the duration is less than 4 hours, which is 60sec*60 mins*4 hours = 14400

I think what you want is:

where missing(instm)

OR (instm - baslintm) < 14400

OR  instm >=  dischatm;

Super Contributor
Posts: 275

Re: Edit check for database validation: How to make sure one variable occurred 4hrs before a different one?

Posted in reply to tkallday33

From your description, I guess, it is more reasonable for your where clause:

where instm is not null and intck('minute', instm,baslintm)>240 and instm>=dischatm;

Ask a Question
Discussion stats
  • 2 replies
  • 317 views
  • 0 likes
  • 3 in conversation