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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.