# ADLB Analysis Visitn Number

**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 visits. 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 the same day or additional visits in the 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;

ifindex(day,”Additional”) >0thenadd_day=1;ifindex(day,”Additional”) >0thenord=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);ifa ;

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;ifadd_day=1thenavisitn=.;

avisitn1=avisitn;ifindex(visname,”Cycle”) > 0thenavis = input(scan(visname,2,’’),8.);

run;data lb1b;

set lb1a;

by subjid visit visname newdt add_day dayn;

retain avisitn;ifavisitn1^=. or first.subjidthenavisitn=avisitn1;elsedo;ifadd_day=1 and first.daynthenavisitn=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 an unsuccessful try.