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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.