@SASPhile :
It can done only if VALUE is a character variable. Is it? If not, it can be set a a missing value, not a blank. But you can set the system option missing="" and then see numeric missing values as a blank through whatever UI you're using. The code below should work regardless of the data type of VALUE.
First, if stat="n" always on the first record in each ID group, then:
data have ;
input ID Stat $ value ;
cards ;
11 n 20
11 mean 12
11 median 12.5
12 n 0
12 mean 0
12 median 0
;
run ;
option missing = "" ;
data want (drop = _:) ;
do until (last.id) ;
set have ;
by id ;
if first.id and put (cats (value), $1.) = "0" then _setnull = 1 ;
if _setnull and stat in ("mean", "median") then call missing (value) ;
output ;
end ;
run ;
If stat="n" (and also "mean" or "median") can be anywhere within an ID group, then, more generally:
data want (drop = _:) ;
do _n_ = 1 by 1 until (last.id) ;
set have ;
by id ;
if stat = "n" and put (cats (value), $1.) = "0" then _setnull = 1 ;
end ;
do _n_ = 1 to _n_ ;
set have ;
if _setnull and stat in ("mean", "median") then call missing (value) ;
output ;
end ;
run ;
Either way, CATS and CALL MISSING are used to make the code independent of the data type of VALUE.
Kind regards
Paul D.
... View more