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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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 lock in 2025 pricing—just $495!

Register now

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
  • 980 views
  • 3 likes
  • 3 in conversation