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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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