Hello
I have a problem with a relative path in the batch session
When I use the batch session, the following commands are invalid:
%let a = %sysget(SAS_EXECFILEPATH);
%let b = %sysget(SAS_EXECFILENAME);
%let DiskPatch = %sysfunc(tranwrd(&a,Code\&b,));
%let CodePatch = %sysfunc(tranwrd(&a,&b,));
On the internet I found something
%let execpath=" ";
%macro setexecpath;
%let execpath=%sysfunc(GetOption(SYSIN));
%if %length(&execpath)=0
%then %let execpath=%sysget(SAS_EXECFILEPATH);
%mend setexecpath;
%setexecpath;
%put &execpath;
However, I need the path to the file without its name.
I tried this:
%let execpath=" ";
%let execpath1=" ";
%macro setexecpath;
%let execpath=%sysfunc(GetOption(SYSIN));
%let execpath1=%sysfunc(GetOption(SYSIN));
%if %length(&execpath)=0
%then %let execpath=%sysget(SAS_EXECFILEPATH);
%if %length(&execpath1)=0
%then %let execpath1=%sysget(SAS_EXECFILENAME);
%mend setexecpath;
%setexecpath;
%put &execpath;
%put &execpath1;
%let DiskPatch = %sysfunc(tranwrd(&a,Code\&b,));
%let CodePatch = %sysfunc(tranwrd(&a,&b,));
during normal session working properly but in the batch session not received the file name but the entire path
I'll be grateful for the help
Sincerely
Use %sysfunc(pathname(<yourref>)) where yourref is libname filename defined by you /your administrator/ where your data /code is..
Sounds like you want to extract the directory from the full filename? If so then SUBSTR() should work.
%let path=c:\myprogram.sas;
%let program = %scan(&path,-1,/\);
%let directory = %substr(&path,1,%length(&path)-%length(&program));
%put program=&program directory=&directory;
program=myprogram.sas directory=c:\
Thank you. Tour advice very handy
Mine is better than Tom's . Just Kidding .
%let path=c:\temp\myprogram.sas;
%let directory = %sysfunc(prxchange(s/[^\\]+$//,-1,&path));
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.