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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: