STUDY 'DAY' CLCULATION (ONE-LINER)

Recently I stumbled upon a SUGI-Paper  SAS 1-Liners by Stephen Hunt. I liked the way Stephen developed the 1-liner for  STUDY DAY calculation.


One of the most common calculation used across all types of programming is determining a relative 'day' based on 2 date fields. In clinical trials the initial 'Study Day' is generally considered to begin at either randamization or dosing, thus assessments made prior to this starting point require a slight variation in the calculating in order to preserve the typical  'no day 0' concept.


SUGI proceedings10/054-2010.pdf
  When it comes to calculating such, some programmers opt to both with evaluating whether a visit date occurred on or /after randomization.

if visdt > randdt >.z then stydy=visdt-randdt;
else stydt=visdt-randdt+1;

However, this is unnecessary, sine the 1-liner will suffice:

if visdt >.z & randdt >.z then stydy=visdt-randdt+(visdt>=randdt);

Thanks to Stephen  for his code.

Here is the code I use from now to compute the study day.

if nmiss(visidt,randdt)=0 then stydy=visdt-randdt+(visdt>=randdt);

Popular posts from this blog

SAS Interview Questions and Answers: CDISC, SDTM and ADAM etc

Comparing Two Methods for Removing Formats and Informats in SAS: DATA Step vs. PROC DATASETS

Studyday calculation ( --DY Variable in SDTM)