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