BookmarkSubscribeRSS Feed
makset
Obsidian | Level 7

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

4 REPLIES 4
jakarman
Barite | Level 11

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

---->-- ja karman --<-----
Tom
Super User Tom
Super User

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

makset
Obsidian | Level 7

Thank you. Tour advice very handy Smiley Happy

Ksharp
Super User

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

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

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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2370 views
  • 6 likes
  • 4 in conversation