Hi, I have a dataset where i have do last value carry forward by downword rows.
Any leads would be helpful.
data CM;
input USUBJID mmmol_injected;cards;
AUS-001001 520
AUS-001001 0
AUS-001001 .
AUS-001001 .
AUS-001001 .
AUS-001001 100
US-001001 0
US-001001 .
US-001001 100
US-001001 .
US-001001 100
US-001001 .
PAK-001001 70
PAK-001001 80
PAK-001001 0
PAK-001001 0
PAK-001001 .
PAK-001001 80
;
run;
Ok. Try this
data CM;
input USUBJID $10. mmmol_injected;
cards;
AUS-001001 520
AUS-001001 0
AUS-001001 .
AUS-001001 .
AUS-001001 .
AUS-001001 100
US-001001 0
US-001001 .
US-001001 100
US-001001 .
US-001001 100
US-001001 .
PAK-001001 70
PAK-001001 80
PAK-001001 0
PAK-001001 0
PAK-001001 .
PAK-001001 80
;
run;
data want (drop=_:);
set CM;
by USUBJID notsorted;
retain _mm;
if first.USUBJID then _mm=.;
if mmmol_injected ne . then _mm=mmmol_injected;
else if mmmol_injected=. then mmmol_injected=_mm;
run;
You want the last non-missing value carried forward by USUBJID, correct?
I'm not sure I understand the requirement. What does your desired result look like?
Ok. Try this
data CM;
input USUBJID $10. mmmol_injected;
cards;
AUS-001001 520
AUS-001001 0
AUS-001001 .
AUS-001001 .
AUS-001001 .
AUS-001001 100
US-001001 0
US-001001 .
US-001001 100
US-001001 .
US-001001 100
US-001001 .
PAK-001001 70
PAK-001001 80
PAK-001001 0
PAK-001001 0
PAK-001001 .
PAK-001001 80
;
run;
data want (drop=_:);
set CM;
by USUBJID notsorted;
retain _mm;
if first.USUBJID then _mm=.;
if mmmol_injected ne . then _mm=mmmol_injected;
else if mmmol_injected=. then mmmol_injected=_mm;
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!
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.