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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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