I always struggle with the macro quoting etc.
It's impossible for me to understand its behavior.
If I use the path without macro concatenation, it works, but using whatever macro construct (single or double quote) it fails.
%let sess=mysession;
%let caslib=risknoba;
%let table=Assessment data for SAS training diario;
%let ext=xlsx;
%let path=/caslibs/risknoba/;
%let ally="&path.&table..&ext";
cas &sess;
libname caslib cas sessref=&sess;
%put "&path.&table..&ext";
%put &ally;
proc import datafile= &ally.
/* proc import datafile= '&path.&table..&ext' */
/* proc import datafile="/caslibs/risknb/Assessment data for SAS training diario.xlsx" */
out=work.test
dbms=xlsx
replace;
getnames=no;
sheet="Hoja1";
range='B1:D33';
run;
the log info:
1 %studio_hide_wrapper;
82 %let sess=mysession;
83 %let caslib=risknoba;
84 %let table=Assessment data for SAS training diario;
85 %let ext=xlsx;
86 %let path=/caslibs/risknoba/;
87 %let ally="&path.&table..&ext";
88 cas &sess;
WARNING: A session with the name MYSESSION already exists.
89 libname caslib cas sessref=&sess;
NOTE: Libref CASLIB was successfully assigned as follows:
Engine: CAS
Physical Name: xxxxxxx
90
91 %put "&path.&table..&ext";
"/caslibs/risknoba/Assessment data for SAS training diario.xlsx"
92 %put &ally;
"/caslibs/risknoba/Assessment data for SAS training diario.xlsx"
93
94 proc import datafile= &ally.
95 /* proc import datafile= '&path.&table..&ext' */
96 /* proc import datafile="/caslibs/risknb/Assessment data for SAS training diario.xlsx" */
97 out=work.test
98 dbms=xlsx
99 replace;
100 getnames=no;
101 sheet="Hoja1";
102 range='B1:D33';
103 run;
ERROR: Physical file does not exist, /caslibs/risknoba//Assessment data for SAS training diario.
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
104
105 %studio_hide_wrapper;
116
117
Hello @acordes,
@acordes wrote:
92 %put &ally;
"/caslibs/risknoba/Assessment data for SAS training diario.xlsx"
93
94 proc import datafile= &ally.
95 /* proc import datafile= '&path.&table..&ext' */
96 /* proc import datafile="/caslibs/risknb/Assessment data for SAS training diario.xlsx" */
Just to rule out a trivial reason: The name of the directory is really risknoba, not risknb?
Hello @acordes,
@acordes wrote:
92 %put &ally;
"/caslibs/risknoba/Assessment data for SAS training diario.xlsx"
93
94 proc import datafile= &ally.
95 /* proc import datafile= '&path.&table..&ext' */
96 /* proc import datafile="/caslibs/risknb/Assessment data for SAS training diario.xlsx" */
Just to rule out a trivial reason: The name of the directory is really risknoba, not risknb?
OMG
Shame on me 🤣
@acordes wrote:
OMG
Shame on me 🤣
Next bit: Macro variable references do not resolve inside single quotes. So this
95 /* proc import datafile= '&path.&table..&ext' */
to actually use the macro variables would have to be
proc import datafile= "&path.&table..&ext"
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.