ADLB avisitn

Background Story:

In ADLB avisitn means analysis visit number sequence, most of the time it is a standard variable, such that each Visit or Visname maps to a corresponding number. However we had a study with convoluted raw data, in which multiple visits were recorded on the same day or many additional visit.  Today we will go over a basic and an advanced example of ADLB.Avisitn.

Raw LB Data

 

Standard Analysis Visit Number (avisitn):

Key variable: Visname , Avisitn, Day

*Avisitn:

if index(visname,"Cycle") > 0 then AVISITN = input(scan(visname,2,''),8.);
if index(visname,"Baseline") > 0 then AVISITN = 0;
if index(day,"Day 01") > 0 then AVISITN = input(scan(visname,2,''),8.)+0.1;
if index(day,"Day 08") > 0 then AVISITN = input(scan(visname,2,''),8.)+0.2;
if index(visname,'Follow-up 1') then AVISITN = 90;
if index(visname,'Follow-up 2') then AVISITN = 91;

Complex Avisitn:

There are multiple visits in same day or additional visits in same cycle.

Key idea: create intermedia variables mindt, newdt, use the function max, and first.subjid for additional cycle number.

Sample Code:

*Special Case of avisitn;
if index(day,"Additional") >0  then add_day=1;
if index(day,"Additional") >0  then ord=2;

*Sort the visit without additional day;
proc sort data=lb nodupkey out=r(keep=subjid visname adt day visit avisit);
by subjid visit visname day ;
where add_day^=1;
run;

*Set the reference lab date as adt;
data r1;
format mindt date9.;
set r;
mindt=adt;
rename day=daynf avisit=avisitf;
proc sort; by subjid visit visname day adt;
run;

data lb1a;
merge lb1(in=a) r1(in=b);
if a ;
by subjid visit visname day; 
format newdt date9.;
newdt=coalesce(mindt,adt);
run;

proc sort data=lb1a; 
by subjid visit visname newdt add_day dayn;
run;

data lb1a(drop=avisitn);
set lb1a;
if add_day=1 then avisitn=.;
avisitn1=avisitn;
if index(visname,"Cycle") > 0 then avis = input(scan(visname,2,''),8.);
run;

data lb1b;
set lb1a;
by subjid visit visname newdt add_day dayn;
retain avisitn;
if avisitn1^=. or first.subjid then avisitn=avisitn1;
else do;
if add_day=1 and first.dayn then avisitn=max(avisitn, avis)+0.01;
end;
run;

Sample Output:

Note:
Thanks Hongyan for suggesting creating an intermedia variable and code it the universal method. I was trying to code it case by case, which is a unsuccessful try.

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Social media & sharing icons powered by UltimatelySocial
%d bloggers like this: