BookmarkSubscribeRSS Feed
5 REPLIES 5
Bhargav_Movva
Fluorite | Level 6

please make a correction  -->fourth record from last should contain 44 as base value instead of 120

RW9
Diamond | Level 26 RW9
Diamond | Level 26

So its just retaining the row with the word screening?  Then its simple:

data want;
  set lab;
  retain base;
  if visit="screening" then base=lbstresn;
run;

However I suspect its more complicated than that.  I assume your creating an ADaM dataset, so want a baseline flag.  To do this first create a dataset with all the baseline values, then merge this back to your original data.  E.g.

data base (keep=subjid lbtest base_val (rename=(lbstresn=base_val));
  set lab;
  where visit="screening";
run;

data want;
  merge lb base;
  by subjid lbtest;
run;

You can then alter that to keep other variables, do more compicated baseline calculations, LOCF etc.

Astounding
PROC Star

Since you need to inspect both the baseline and predose values, two loops can do the trick:

 

data want;

do until (last.subjid);

   set have;

   by subjid;

   if visit in ('screening', 'predose') and lbstresn > . then base = lbstresn;

end;

do until (last.subjid);

   set have;

   by subjid;

   output;

end;

run;

Bhargav_Movva
Fluorite | Level 6

hey thank you so much it worked.But still i didnt understood the trick of two loops .please explain.Thanks

Astounding
PROC Star

The top loop reads through all the observations for a subject.  Whenever it finds a nonmissing value (for selected visit types) it updates BASE.  So BASE is established at that point.

 

Then the bottom DO loop reads exactly the same observations.  (When a DATA step contains multiple SET statements, each one operates independently of the other.)  It outputs those observations, along with the previously calculated value for BASE.

 

If you want to find more examples like this, you can search for DOW loops.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1657 views
  • 1 like
  • 3 in conversation