cancel
Turn on suggestions
Showing results for
Search instead for
Did you mean:
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Calcite | Level 5

I need to replace all the missing values (in previous instances) with the latest instance values

ID Start End

1 3/4/2022

1 3/5/2022 3/6/2022

needs to looks like -

ID Start End

1 3/4/2022 3/6/2022

1 3/5/2022 3/6/2022

0 Likes
1 ACCEPTED SOLUTION

Accepted Solutions
Opal | Level 21

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;
PG
3 REPLIES 3
Opal | Level 21

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;
PG
Calcite | Level 5

@PGStats Thank you so much! this worked

0 Likes
PROC Star

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;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sasinnovate.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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ドル!

Register now

Call for Content EXTENDED

Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.

Submit your proposal!

How to connect to databases in SAS Viya

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.

Discussion stats
[フレーム]

AltStyle によって変換されたページ (->オリジナル) /