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’ ?
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;
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;
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!
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.