Discover More Tips and Techniques on This Blog

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

Disclosure:

In the spirit of transparency and innovation, I want to share that some of the content on this blog is generated with the assistance of ChatGPT, an AI language model developed by OpenAI. While I use this tool to help brainstorm ideas and draft content, every post is carefully reviewed, edited, and personalized by me to ensure it aligns with my voice, values, and the needs of my readers. My goal is to provide you with accurate, valuable, and engaging content, and I believe that using AI as a creative aid helps achieve that. If you have any questions or feedback about this approach, feel free to reach out. Your trust and satisfaction are my top priorities.