I have wirte a macro to important all xlsx in "C:\SASMACRO\data\F2+Blank\" and read them and merged in a dataset called "a."
However, I have problems is that the file dataset with one variable (filenames), which cannot read the blank.
So, if a xlsx data called "data 01", then it cannot read.
Can some one help me to improve the problems that I can important xlsx file with blank in its name.
Thx.
%macro merge();
proc sql noprint;select count(filenames) INTO :myn from File;
%do i=1 %to &myn;
proc import out=datafile&i datafile="&&file&i" dbms=xlsx /*any data type*/replace;
run;
%end;
data a;
set %do j=1 %to &myn;
datafile&j
%end;
;
run;
%mend merge;
filename lib pipe 'dir "C:\SASMACRO\data\F2+Blank\*.xlsx" /b';
data file;
length filenames $ 40;
infile lib truncover;
input filenames : $;
filenames="C:\SASMACRO\data\F2+Blank\"||filenames;
run;
data _NULL_;
set file;
call symputx('file'||put(_n_,1.),filenames,'G');
run;
options sasautos=work;
%merge()
/*data would be merged in a*/
Simplfying your code will help you. Also note it is never a good idea to have any special characters in filenames or paths.
filename lib pipe 'dir "C:\SASMACRO\data\F2+Blank\*.xlsx" /b'; data file; infile lib truncover; input; call execute('proc import datafile="C:\SASMACRO\data\F2+Blank\"'||strip(_infile_)||'" out=inter dbms=xlsx; run;'); call execute('data want; set want inter; run;');
run;
You will note that each iteration creates inter, then that gets set to want (want should be created before this step!).
Simplfying your code will help you. Also note it is never a good idea to have any special characters in filenames or paths.
filename lib pipe 'dir "C:\SASMACRO\data\F2+Blank\*.xlsx" /b'; data file; infile lib truncover; input; call execute('proc import datafile="C:\SASMACRO\data\F2+Blank\"'||strip(_infile_)||'" out=inter dbms=xlsx; run;'); call execute('data want; set want inter; run;');
run;
You will note that each iteration creates inter, then that gets set to want (want should be created before this step!).
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.