BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
2 REPLIES 2
deleted_user
Not applicable
It is a baselining variable.

What it is doing, or will do if you had more data, is storing the Range Indicator of Week 0 for each set and then augmenting the Week 0 Range Indicator to subsequent weeks for the same set. Then when the week is reset to 0, assuming a new set, it re-establishes the Week 0 Baseline and augments that to the next set.

Most likely, this is done for later comparision analysis, if the results change from the Week 0 baseline, {Week 1 in your example] you can easily query when that happens, since (lbrefind NEQ baseflag)

Set being defined as a {subjid, lbcat, lbtest, lbresu} tuple.

Ike
deleted_user
Not applicable
Thank you very much for the explanation. I appreciate it.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 2 replies
  • 5893 views
  • 0 likes
  • 1 in conversation