BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

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;
2 REPLIES 2
novinosrin
Tourmaline | Level 20
data want;
set two;
retain _a;
if not missing(a) then _a=a;
else a=_a;
drop _a;
run;
SuryaKiran
Meteorite | Level 14

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;
Thanks,
Suryakiran
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 973 views
  • 3 likes
  • 3 in conversation