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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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