Hello community,
I have a program that worked very well in SAS Unniversity edition, but now in SAS onDemand for academics it no longer works.
I send some parameters to the macro and when the macro variables are concatenated to form the path of the file in some mysterious way a "//" is added to the path so the file cannot be found.
I show you the code and the error of the log.
Source
%macro import_emitidas_xls(rfc,anio,mes); FILENAME REFFILE "/home/u58941115/cont/pmfecu/entradas/&rfc._Emitidas_&anio._&mes..xlsx"; PROC IMPORT DATAFILE=REFFILE DBMS=XLSX OUT=WORK.&rfc._Emitidas_&anio._&mes ; GETNAMES=YES; SHEET="XML"; RUN; %mend import_emitidas_xls; %let rfc= XBG1311088L6; %let anio=2021; %let mes= 01; %import_emitidas_xls(&rfc,&anio,&mes);
Log
ERROR: Physical file does not exist, /home/u58941115/cont/pmfecu/entradas//XBG1311088L6_Emitidas_2021_01.
NOTE: The SAS System stopped processing this step because of errors.
Step 1 of macro development: start with working non-macro code:
filename reffile "/home/u58941115/cont/pmfecu/entradas/XBG1311088L6_Emitidas_2021_01.xlsx";
proc import
datafile=reffile
dbms=xlsx
out=WORK.XBG1311088L6_Emitidas_2021_01
replace
;
getnames=yes;
sheet="XML";
run;
Once this works, proceed from there.
One slash is added, not two.
The code shown should not generate this error.
Please turn on option MPRINT and show us the full log report created by this code.
Step 1 of macro development: start with working non-macro code:
filename reffile "/home/u58941115/cont/pmfecu/entradas/XBG1311088L6_Emitidas_2021_01.xlsx";
proc import
datafile=reffile
dbms=xlsx
out=WORK.XBG1311088L6_Emitidas_2021_01
replace
;
getnames=yes;
sheet="XML";
run;
Once this works, proceed from there.
You're absolutely right Kurt. The error is in the name of the physical file. The code had no problems. I got caught up in the LOG message and thought that by forming the filename with the macro variables I was adding a "/" in some strange way.
Thank you very much for your recommendation!
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.