data gd;
input id$ visit sbp dbp;
cards;
001 10 120 90
001 10 110 .
001 10 130 .
001 20 110 90
001 30 110 98
002 10 120 .
002 10 110 80
002 10 130 98
002 20 110 90
002 30 110 98
003 10 120 90
003 10 110 80
003 10 130 98
003 10 110 90
003 20 120 .
003 30 110 98
;
run;
For a subject if sys, dbp is missing after first record we need to return first value to it missing value to it next records. If first record is also missing for a subject we need to set to missing.
My Code:
proc sort data=gd;by id visit;run;
data gd4;
set gd;
by id visit;
if first.id;
b=dbp;
run;
data gd6;
merge gd gd4;
by id;
/*if missing(dbp) then dbp=b;*/
/*else b=dbp;*/
/*b=dbp;*/
run;
Look up RETAIN
I find part of your problem description a bit ambiguous. You said (bold-italics are mine)
For a subject if sys, dbp is missing after first record we need to return first value to it missing value to it next records. If first record is also missing for a subject we need to set to missing.
What do you mean by "first record is also missing"? That it is missing in addition to a later missing obs? Do you mean if first obs is missing, then all obs should be set to missing? Please give an example of desired output:
Required Output:
data gd;
input id$ visit sbp dbp;
cards;
001 10 120 90
001 10 110 90
001 10 130 90
001 20 110 90
001 30 110 98
002 10 120 .
002 10 110 80
002 10 130 98
002 20 110 90
002 30 110 98
003 10 120 90
003 10 110 80
003 10 130 98
003 10 110 90
003 20 120 90
003 30 110 98
;
run;
Retain Y;
if not missing(dbp) or first.ID then Y=dbp;
Thanks Reeza....
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!
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.