I have a sas macro that use proc import to load multiple .xlsx files and it worked pretty well before. Today, I have a bunch more .xlsx files files that need to be loaded. So, I used the same macro idea. But this time it created a problem and couldn't run through. Here is the sas code:
*name q3 file path;
filename file01 '/home/myname/gcs_coded/Los Angeles_CA_Q3_English_EF.xlsx';
filename file02 '/home/myname/gcs_coded/Los Angeles_CA_Q3_English_Prime.xlsx';
filename file03 '/home/myname/gcs_coded/Los Angeles_CA_Q3_Spanish_ET.xlsx';
filename file04 '/home/myname/gcs_coded/Los Angeles_CA_Q3_Spanish_Prime.xlsx';
%macro load (id=, filename= );
proc import out = &id
datafile = &filename
dbms = xlsx
replace;
sheet = "sheet1";
getnames = yes;
run;
%mend load;
%load (id=q3_01, filename=file01);
and here is the erro message:
ERROR: XLSX file does not exist -> /FILE01.xlsx
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
But very interestingly, I then took out the second marco parameter but just copy in the file link, like the following, it runs well, which means the link is alright and the file exits.
%macro load (id= );
proc import out = &id
datafile = '/home/myname/gcs_coded/Los Angeles_CA_Q3_English_EF.xlsx'
dbms = xlsx
replace;
sheet = "sheet1";
getnames = yes;
run;
%mend load;
%load (id=q3_01)
Let me know what you guys think. Thanks
As far as I can tell, proc import doesn't recognize a fileref referring to a .xlsx file. I tried using a fileref to import a csv and it worked, then a .xls file and it worked, but it did not work with a .xlsx file. So to import a fileref you seemingly have to follow datafile =
with the literal path, not a fileref referring to the path. One way around this would be to store the file names to macro variables, like so:
*name q3 file path;
%let file01 = '/home/myname/gcs_coded/Los Angeles_CA_Q3_English_EF.xlsx';
Then when you are calling the macro (which you don't need to change), have filename equal the macro variable for the file:
%load (id=q3_01, filename=&file01);