Hello:
I am trying to read in several SAS datasets for US states, each with a filename that has the format <statename>births i.e. ARnew, AZnew, CAnew,
I have 45 such datasets that I want to combine. I am using a do-loop for this but get an error saying "work.set.data. does not exist". What am I doing wrong?
libname proj '... ';
%let statelist=%str(ak,ar,al,.....wi,wv);
%macro combine;
data test;
%do k=1 %to 45;
%let state=%sysfunc(strip(%sysfunc(scan(&statelist,&k,','))));
set proj.&state.new
%end;
;
run;
%mend;
%combine;
Thanks
Dana
I made the change but this didn't work.
libname proj '... ';
%let statelist=%str(ak,ar,al,.....wi,wv);
%macro combine;
data test;
%do k=1 %to 45;
set
%let state=%sysfunc(strip(%sysfunc(scan(&statelist,&k,','))));
proj.&state.new
%end;
;
run;
%mend;
%combine;
I still get the message
"work.set.data does not exist."
The word SET does not belong inside the %DO loop. Move it to before the %DO statement, leaving everything else as is.
One thing do check with unexpected macro results is to turn on the macro inspection options:
If you tried:
options mprint;
%combine;
You would likely find in the log:
Set proj.aknew set proj.arnew and so forth.
YOu did not put your SET in the correct place so SAS thinks you are looking for a data set name SET.
Use:
set
%let state=%sysfunc(strip(%sysfunc(scan(&statelist,&k,','))));
proj.&state.new
%end;
; /* now this ; properly closes the SET statement*/
I made the change but this didn't work.
libname proj '... ';
%let statelist=%str(ak,ar,al,.....wi,wv);
%macro combine;
data test;
%do k=1 %to 45;
set
%let state=%sysfunc(strip(%sysfunc(scan(&statelist,&k,','))));
proj.&state.new
%end;
;
run;
%mend;
%combine;
I still get the message
"work.set.data does not exist."
The word SET does not belong inside the %DO loop. Move it to before the %DO statement, leaving everything else as is.
copy and paste lost the %do loop. sorry. Yes SET OUTSIDE the do loop per Astounding.
Thank You to ballardw & astounding!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.