I have received a dataset like below:
Dataset is sorted by Cal_date but the rows are blank after the first row is populated. I am trying to populate the remaining rows with the previous date... until the next date starts...
Cal Date | Resource Name |
01/02/2019 | B |
. | B |
. | B |
01/03/2019 | B |
I put a variable flag = 0 where cal_date = . but i am stuck
I am trying below but not working... any direction would be appreciated
data want;
set test;
format newdate date9.;
retain lag_date;
lag_date = cal_date;
if flag =1 then newdate = lag_date;
drop lag_date;
run;
data have;
input (Cal_Date Resource_Name) (:$10.);
cards;
01/02/2019 B
. D
. C
01/03/2019 E
. E
;
data want;
set have;
retain _date;
if not missing(Cal_Date) then _date=cal_date;
else cal_date=_date;
drop _date;
run;
data have;
input (Cal_Date Resource_Name) (:$10.);
cards;
01/02/2019 B
. B
. B
01/03/2019 B
;
data want;
update have(obs=0) have;
by Resource_Name;
output;
run;
Thanks for the quick reply... i think i may have simplified it too much.. the resource_names can be different. I just need the dates to keep populating until the new dates starts
input
Cal Date | Resource Name |
01/02/2019 | B |
. | D |
. | C |
01/03/2019 | E |
. | E |
output needed
Cal Date | Resource Name |
01/02/2019 | B |
01/02/2019 | D |
01/02/2019 | C |
01/03/2019 | E |
01/03/2019 | E |
data have;
input (Cal_Date Resource_Name) (:$10.);
cards;
01/02/2019 B
. D
. C
01/03/2019 E
. E
;
data want;
set have;
retain _date;
if not missing(Cal_Date) then _date=cal_date;
else cal_date=_date;
drop _date;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.