Reputation: 1438
To get the file name of the current SAS program we can write
%put %sysget(SAS_EXECFILEPATH);
I am so unfortunate that someone once created a directory that included an ampersand in the path (yikes!). Let us create an example folder C:\temp&other
and store our test.sas
program here in that folder.
Now, my question is:
%sysget(SAS_EXECFILEPATH)
to avoid SAS trying to resolve a macro variable &other
?The easy solution would be to change the path name but things are unfortunately not always easy and I am not allowed to change the folder name.
My attempts:
None of the nr
functions I have tried help me, since they mask both %
and &
. I have tried the following (indented line is the SAS log output). Note that %NRQUOTE
outputs the same as the "naked" call.
%put %sysget(SAS_EXECFILEPATH);
/* WARNING: Apparent symbolic reference OTHER not resolved. */
/* C:\temp&other\test.sas */
%put %nrstr(%sysget(SAS_EXECFILEPATH));
/* %nrstr(%sysget(SAS_EXECFILEPATH)) */
%put %nrquote(%sysget(SAS_EXECFILEPATH));
/* WARNING: Apparent symbolic reference OTHER not resolved. */
/* C:\temp&other\test.sas */
%put %superq(%sysget(SAS_EXECFILEPATH));
/* WARNING: Apparent symbolic reference OTHER not resolved.*/
/* ERROR: Invalid symbolic variable name C\TEST&OTHER\TEST.SAS. */
Upvotes: 2
Views: 351
Reputation: 51601
To eliminate the warning about the undefined macro variable (and worse the possibility of it actually finding and using an existing macro variable) you will need to use the SAS function SYSGET() instead of the macro function %SYSGET().
If you cannot run SAS code then you can use the macro function %QSYSFUNC() to run the SAS function and quote the returned value.
%put %qsysfunc(sysget(SAS_EXECFILEPATH));
If might even be useful to define a macro "function" %qsysget() in your personal autocall library. Perhaps something like this:
%macro qsysget(name);
%if -1=%sysfunc(envlen(&name)) %then %put WARNING: Environment variable "&name" not found.;
%else %qsysfunc(sysget(&name));
%mend;
Upvotes: 4
Reputation: 12909
Use a data _null_
step with call symputx
to create a macro variable that holds the value of sas_execfilepath
. You can then resolve it with %superq()
.
data _null_;
call symputx('sas_execfilepath', sysget('sas_execfilepath'));
run;
%put %superq(sas_execfilepath);
Log output:
C:\temp&other\test.sas
Upvotes: 5