Good day,
I have old data with different format and updating it with new. Idea is that variable WantedName had been written with underscore Wanted_Name whereas new data is without this. No big deal I though.
EDIT: WantedName and Wanted_Name are SAS dates.
Original data:
year Wanted_Name
2013 1234
2013 4321
2013 3241
and from year 2015 forward:
year WantedName
2015 5678
2015 8765
....
I tried the logic:
%macro macro_env;
data _null_;
call symput ("curr_year", year(date()) );
run;
data long_data;
set
%do year=2013 %to &curr_year.;
data.history&year.
%end;
;
WantedName=COALESCE(WantedName, Wanted_Name);
run;
%mend macro_env;
Nope. Did not work. For some reason it took the first value of Wanted_Name and pasted that over the whole data range except for the new data:
year Wanted_Name WantedName
2013 1234 1234
2013 4321 1234
2013 3241 1234
....
2015 . 5678
2015 . 8765
Now I managed to fix the issue by removing the coalesce function and adding a additional data statement:
data long_data;
set
%do year=2013 %to &curr_year.;
data.history&year.
%end;
;
run;
data long_data;
set long_data;
WantedName=COALESCE(WantedName, Wanted_Name);
run;
Question: What happens or why isn't the original macro_env working?
I thought datasets in set were first loaded and then function applied. (Which is working in the latter data statement. Apparently not... Maybe?