Amazingly enough the function is RETAIN, but you want to use it with a new variable.
data have; input Test $ Result; datalines; A 12.6 A . A . A . A . B 14.9 B . B . B . B . B . ; data want; set have; by test notsorted; retain tempresult; if first.test then tempresult=.; if not missing(result) then tempresult=result; if missing (result) then result=tempresult; drop tempresult; run;
The data step creates a set similar to your description.
The BY statement in the Want data step assumes that your data is grouped by Test value if not actually sorted.
Retain creates a variable that will hold values. If the value is to be character you should define the length before the Retain statement.
The BY statement creates automatic variable that you can test to see if an observation is the first or last of a group. In this case it is used to reset the retained variable when the Test value changes to a new group.
Use a RETAINed variable which you discard later.
data want;
set have;
by test;
retain _result;
if first.test then _result = .;
if result ne .
then _result = result;
else result = _result;
drop _result;
run;
Amazingly enough the function is RETAIN, but you want to use it with a new variable.
data have; input Test $ Result; datalines; A 12.6 A . A . A . A . B 14.9 B . B . B . B . B . ; data want; set have; by test notsorted; retain tempresult; if first.test then tempresult=.; if not missing(result) then tempresult=result; if missing (result) then result=tempresult; drop tempresult; run;
The data step creates a set similar to your description.
The BY statement in the Want data step assumes that your data is grouped by Test value if not actually sorted.
Retain creates a variable that will hold values. If the value is to be character you should define the length before the Retain statement.
The BY statement creates automatic variable that you can test to see if an observation is the first or last of a group. In this case it is used to reset the retained variable when the Test value changes to a new group.
data have; input Test $ Result; datalines; A 12.6 A . A . A . A . B 14.9 B . B . B . B . B . ; data want; update have(obs=0) have; by Test; output; run;
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!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.