BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
havmaage
Obsidian | Level 7

Hi, 

I have been looking on how to include sas files in my program to a parent directory regardless from where it is executed 

 

if i check my sas progrtam out to c:\temp then c:\temp is my current folder 

in my code i include some macro sas files i want to have access to in my programs 

 

 

filename mmacros "..\macros\*.sas";
%include mmacros/source2;

That doent work 

then i tried to look id i could use 

 

%put %sysget(SAS_EXECFILEPATH);

This only runs in batch mode, so i will assume this will work when i run from OPC/Tivoli Scheduler 

 

Then i tried to refer to 

%put &_SASPROGRAMFILE;

This macro is not initialized or look empty. 

 

i am on SAS 9.2 with SAS-EG 4.3 logged into a metadata server also  windows. 

 

ism it possible to get the current path where the file i execute is located from SAS-EG program. 

nb: i only use SAS-EG as an IDE my code will run as base sas code. 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

@havmaage - We use exactly the same development approach as you - EG for IDE and batch for production work.

 

We have a common SAS "control" program that sets up the application environment across all our SAS jobs regardless of whether it is run in EG or batch or SAS Studio. That control program contains SAS macro variables defining all of the folder locations from where to read SAS programs, SAS macros and so on as well as where to write application output to.

 

By running this program first in all of your EG and batch jobs you can be guaranteed that the right SAS programs will be found and the folder definitions are only defined once in one program for easy maintenance. If you wanted to you could make this control program an AUTOEXEC that would be run automatically every time you started SAS. This type of approach will take you much further than the limited options of system macro variables. 

View solution in original post

8 REPLIES 8
Tom
Super User Tom
Super User

I don't understand how you are running these programs. The beginning of your post made it sound like you were signed into a terminal and copying files and the running SAS from the command line.  But then you mentioned using Enterprise Guide.  That is a client tool for submitting code to a SAS session.  It does not really support the first mode you described.

 

If you want to know the name of the code you are running from Enterprise Guide there should be a macro variable that the pre-submit code that EG adds that should contain something about what you are running in EG.  But that would only have the location of the file on the machine where EG is running, not on the machine where SAS is running.

 

You probably should just set your own macro variable and use that.

%let topnode=C:\Temp;
filename mmacros "&topnode\macros\*.sas";
%include mmacros/source2;

 

Tom
Super User Tom
Super User

Are you really running such an ancient version of SAS and Enterprise Guide?

SAS 9.2 was replaced over 9 years ago.  https://blogs.sas.com/content/iml/2013/08/02/how-old-is-your-version-of-sas-release-dates-for-sas-so...

 

SASKiwi
PROC Star

I don't follow your logic. For SAS to know what your current program path is you first have to read it into EG. Once you have, then the macro variable _SASPROGRAMFILE will be populated with the folder location and name of the program. If you haven't yet read in a program then  _SASPROGRAMFILE won't be populated.

 

As @Tom has already described, it is good practice to define an absolute program path at the top of your program as a macro variable, then you can make use of it in any programs you run in that SAS session. You could also add this macro variable definition to EG's AUTOEXEC process to ensure it is available automatically every time you open EG.

havmaage
Obsidian | Level 7

just to make it Clear, i am using enterprise guide as an IDE to create sas programs that will run in batch mode submitted from OPC. At my company desktop i have base sas 9.2 and saseg 43 at my disposal. 

 

 

 

 

 

 

andreas_lds
Jade | Level 19

While in EG you could use &_ClientProjectPath to get path and name of the project-file. Unfortunately that variable is not available in any session not started by Enterprise Guide. So you could write a data-step figuring out in which automatic macro-variables are available and extract the information from those variables. It is somewhat disappointing that sas has not clean-up that mess with version 9.3, but it got even worse with 9.4 with more variables that exist in one type of session, but not in others. And adding the current path to the program-code is an absolute no-go, because that would imply the need to edit code before it can be run and code must not be changed when transferring it, from development to testing or even production environments.

SASKiwi
PROC Star

@havmaage - We use exactly the same development approach as you - EG for IDE and batch for production work.

 

We have a common SAS "control" program that sets up the application environment across all our SAS jobs regardless of whether it is run in EG or batch or SAS Studio. That control program contains SAS macro variables defining all of the folder locations from where to read SAS programs, SAS macros and so on as well as where to write application output to.

 

By running this program first in all of your EG and batch jobs you can be guaranteed that the right SAS programs will be found and the folder definitions are only defined once in one program for easy maintenance. If you wanted to you could make this control program an AUTOEXEC that would be run automatically every time you started SAS. This type of approach will take you much further than the limited options of system macro variables. 

havmaage
Obsidian | Level 7

Hi @SASKiwi 

Thanks, it think your description will be somewhat similar to what we want to do.  

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 8 replies
  • 3553 views
  • 4 likes
  • 5 in conversation