BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello,

Let's say that I have 2 SAS programs: "Program1",  "Program2".

Let's say that within the code of "Program1" I want to write a command (statement) to run "Program2"

It means that When "program1" is running then "Program2" will run two and I don't need to open "program2" in order to run it.

For that task I need to write include statement as following:

%include "/path/program.sas";

The problem that I don't know the path of "Program2"

I wrote 

%let rc = %sysfunc(filename(fr,.));
%let curdir = %sysfunc(pathname(&fr));

and got 

/usr/local/SAS/Config/Lev1/LabRet

Then I tried 

%include "/usr/local/SAS/Config/Lev1/LabRet/program1.SAS";

and got error

WARNING: Physical file does not exist, /usr/local/SAS/Config/Lev1/LabRet/program1.SAS.
ERROR: Cannot open %INCLUDE file /usr/local/SAS/Config/Lev1/LabRet/program1.SAS.

My question:

How can I find the correct path to my sas program?

Please

4 REPLIES 4
andreas_lds
Jade | Level 19

Depends on the application used to execute code. Run %put _all_; to get all macro-variable, in SAS Studio and Display Manager there should be a variable named "_SASPROGRAMFILE" pointing to the path of the current program. Using string function to extract the path shouldn't be difficult. In EG 8.3 I see that variable, too.

Patrick
Opal | Level 21

Why don't you know where your programs are stored? Are you eventually trying to include code that only exists in your client side EG/Studio project but not on the file system as a file?

Quentin
Super User

I'm confused.  Looks like your code is running on linux SAS.  What client are you using to submit code? (EG, studio, etc)?  

 

Where is program1.sas stored?  

 

Where is program2.sas stored?

 

Are you saying you know that program1.sas and program2.sas are stored in the same directory, but you don't want to hard-code the path?

 

If you have a standard directory structure that stores your code for each project, one option is to make a macro var with the path to the code directory, e.g.:

 

%let CodeDir= /home/mystuff/ProjectFoo/Code ;

 

So you hard code the directory one place, but then can use the macro variable in filename statement, include statement, etc.  

 

You can often avoid hard-coding completely, but the solution depends on your client, and the setup of your file structures.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.
Reeza
Super User

@Ronein wrote:
 open %INCLUDE file /usr/local/SAS/Config/Lev1/LabRet/program1.SAS.

My question:

How can I find the correct path to my sas program?

Please


I'm guessing your path is relative and in the same folder as program 1? Or is it a level above, below? You have to know where it should be relative to the running program or know the absolute path to reference it.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1012 views
  • 2 likes
  • 5 in conversation