The double DOW technique is well suited for this kind of operation:
data have;
input ID (Start End) (:mmddyy.);
format start end yymmdd10.;
datalines;
1 3/4/2022 .
1 3/5/2022 3/6/2022
;
data want;
do until (last.id);
set have; by id;
if not missing(end) then latest = max(latest, end);
end;
do until (last.id);
set have; by id;
end = coalesce(end, latest);
output;
end;
drop latest;
run;
The double DOW technique is well suited for this kind of operation:
data have;
input ID (Start End) (:mmddyy.);
format start end yymmdd10.;
datalines;
1 3/4/2022 .
1 3/5/2022 3/6/2022
;
data want;
do until (last.id);
set have; by id;
if not missing(end) then latest = max(latest, end);
end;
do until (last.id);
set have; by id;
end = coalesce(end, latest);
output;
end;
drop latest;
run;
The double DOW, as @PGStats suggests is well suited to your task.
The core logic of the double DOW is to read all obs for each ID twice, the first time to establish the latest END value, and the second time to assign that value when necessary.
The code below also reads each ID twice, but uses the "IN=" dataset name parameters (in the SET statement) to identify the equivalent of each DO loop:
data have;
input ID (Start End) (:mmddyy.);
format start end yymmdd10.;
datalines;
1 3/4/2022 .
1 3/5/2022 3/6/2022
run;
data want (drop=_:);
set have (in=firstpass) have (in=secondpass);
by id;
retain _last_end;
if first.id then call missing(_last_end);
if firstpass then _last_end=coalesce(end,_last_end);
if secondpass;
end=coalesce(end,_last_end);
run;
sasinnovate.png
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just 495ドル!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.