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;
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.
Ready to level-up your skills? Choose your own adventure.