DATA Step, Macro, Functions and more

problem with relative path in the batch session

Reply
Contributor
Posts: 28

problem with relative path in the batch session

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

Valued Guide
Posts: 3,208

Re: problem with relative path in the batch session

Use %sysfunc(pathname(<yourref>))  where yourref is libname filename defined by you /your administrator/ where your data /code is..

---->-- ja karman --<-----
Super User
Super User
Posts: 6,502

Re: problem with relative path in the batch session

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:\

Contributor
Posts: 28

Re: problem with relative path in the batch session

Thank you. Tour advice very handy Smiley Happy

Super User
Posts: 9,687

Re: problem with relative path in the batch session

Mine is better than Tom's .Smiley Happy   Just Kidding .

%let path=c:\temp\myprogram.sas;

%let directory = %sysfunc(prxchange(s/[^\\]+$//,-1,&path));

Ask a Question
Discussion stats
  • 4 replies
  • 428 views
  • 6 likes
  • 4 in conversation