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));
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.