Dear,
I created a data set 'two' which is similar to what i am working. I need help in data three. The retain and lag function are not getting the output I need. Please help. Thank you
I need to populate variable 'a' from previous value if missing
output needed;
a 1
a 2
a 3
d 4
d 5
g 6
;
data one;
input a $ b ;
datalines;
a 1
b 2
c 3
d 4
e 5
g 6
;
data two;
set one;
if b in (2,3,5) then a='';
run;
data three;
set two;
retain c;
c=lag(a);
if a ='' then a=lag(c);
run;
data want;
set two;
retain _a;
if not missing(a) then _a=a;
else a=_a;
drop _a;
run;
Just assign C when not missing and retain those until the next non-missing.
data three;
set two;
retain c;
if not missing(a) then c=a;
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.