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;
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 save with the early bird rate—just $795!
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.