Hi all,
I have a piece of SAS program I find difficult to understand. I am in the process of creating a Laboratory Shift Table.
I have two datasets: dataset treat (variables are subjid and trtcode) and a lab dataset (variables are subjid, lbcat, lbtest, lbsu, lbresu, lbnrlw, lbnrhi, lbrefind, wk).
subjid-Subject ID
trtcode- treatment code (0 for placebo and 1 for Active)
lbcat- Lab test category (eg. Hematology)
lbtest-Lab test (eg. Hematocrit, hemoglobin, etc)
lbsu- Standard units
lbresu-lab result in std units
lbnrlo-normal range lower limit
lbnrhi-normal range higher limit
lbrefind-Range indicator (eg. L for low, N for normal, H for high)
wk=week (values are 0,1, 2, 3, 4)
I could merge both both datsets after sorting and got the desired output. I do not understand the need of the following code:
dataset lb is the result of merge
data lb;
set lb;
by subjid lbcat lbtest lbresu wk;
retain baseflag " ";
if first.lbtest then
baseflag = " ";
if week = 0 then
baseflag = lbrefind;
run;
Just after merge, the dataset has the following structure
subjid lbcat lbtest lbsu lbresu lbnrlo lbnrhi lbrefind wk trtcode
100 Hemat hemog g/dL 11.5 11.7 15.9 L 0 1
100 Hemat hemog g/dL 13.2 11.7 15.9 N 1 1
100 Hemat hemog g/dL 13.7 11.7 15.9 N 2 1
100 Hemat hemog g/dL 13.9 11.7 15.9 N 3 1
100 Hemat hemog g/dL 14.0 11.7 15.9 N 4 1
But after subitting the above code which introduces the baseflag variable, the dataset has the following structure :
subjid lbcat lbtest lbsu lbresu lbnrlo lbnrhi lbrefind wk trtcode baseflag
100 Hemat hemog g/dL 11.5 11.7 15.9 L 0 1 L
100 Hemat hemog g/dL 13.2 11.7 15.9 N 1 1 L
100 Hemat hemog g/dL 13.7 11.7 15.9 N 2 1 L
100 Hemat hemog g/dL 13.9 11.7 15.9 N 3 1 L
100 Hemat hemog g/dL 14.0 11.7 15.9 N 4 1 L
I undertstand that this happened because of the retain statement. My question is that why do we need to introduce this flag? I will be soon working on lab shift table, and I am just trying to get familiar.
Any input is highly appreciated.
Thanks,
Cathy