BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MG18
Lapis Lazuli | Level 10

In a table 3 variables are there

Month

Emp_name

Salary

Jan

Aaaa

100

Jan

Bbbb

200

Jan

 

200

Jan

 

400

Jan

Dddd

400

 

How to replace missing Emp_name with the previous latest Emp_name? Means 4th and 5th record of Emp_Name should be replace with ‘bbbb’ ?

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

Hi @MG18 

 

You can use the retain statement to create a temporary variable as follows:

 

data have;
	infile datalines dlm=" " dsd missover;
	input Month $ Emp_name $ Salary;
	datalines;
Jan Aaaa 100
Jan Bbbb 200
Jan  200
Jan  400
Jan Dddd 400
;
run;

data want;
	set have;
	retain _Emp_name;
	if not missing(Emp_name) then _Emp_name = Emp_name;
	else Emp_name = _Emp_name;
	drop _Emp_name;
run;

View solution in original post

1 REPLY 1
ed_sas_member
Meteorite | Level 14

Hi @MG18 

 

You can use the retain statement to create a temporary variable as follows:

 

data have;
	infile datalines dlm=" " dsd missover;
	input Month $ Emp_name $ Salary;
	datalines;
Jan Aaaa 100
Jan Bbbb 200
Jan  200
Jan  400
Jan Dddd 400
;
run;

data want;
	set have;
	retain _Emp_name;
	if not missing(Emp_name) then _Emp_name = Emp_name;
	else Emp_name = _Emp_name;
	drop _Emp_name;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 1621 views
  • 1 like
  • 2 in conversation