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

Hello,

 

I have a macro call at the start of my program. This macro is stored in my study folder:

C:Project\Study\Test\grabpath.sas

 

%macro grabpath;

     %global gpath;
      %let gpth= %sysget(SAS_EXECFILEPATH);
%mend grabpath;

 

 

At the start of my program, the macro is called:

%grabpath;

 

it does not work because the macro is not compiled.

Is there a way to compile the macro when it is called so that with &gpath return the directory path so that the path is not required to be entered manually?

so thta is I wnat to call the setup.sas file I only write

%include "&gpath/setup.sas"  instead of %include "C:Project\Study\Test\setup.sas"

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

I have directories like:

C:\Projects\Project1\Code

C:\Projects\Project1\Code\Macros

C:\Projects\Project2\Code

C:\Projects\Project2\Code\Macros

...

C:\Projects\Common\Code

C:\Projects\Common\Code\Macros

 

I put my shared autocall macros in to C:\Projects\Common\Code\Macros.  That's where I would put grabpath.sas, because it's used across projects.

 

On windows, I edit my config file to point to the folder.  Even though the config file says don't edit below this line.  Because I'm a rebel.

 

So my config file has a line like:

-SET SASAUTOS (
        "C:\Projects\Common\Code\Macros"        
        "!SASROOT\core\sasmacro"
        "!SASROOT\graph\sasmacro"
        "!SASROOT\iml\sasmacro"
        "!SASROOT\qc\sasmacro"
        "!SASROOT\stat\sasmacro"
        )

That way every SAS session I start with this config file has my utility autocall library available.

 

Then in a program where the code is stored in a projectN \Code directory, you could call your grabpath macro, and use it to %include your setup code:

%grabpath;

%include "&gpath/setup.sas"  ; 

And assuming setup.sas is just setup-code, it would include a line like below to add the project-specific macro library to the search path:

*add project-specific macro library to front of search path;
options insert=sasautos=("&gpath\Macros") ;

 

 

 

 

 

 

 

 

 

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

View solution in original post

7 REPLIES 7
Astounding
PROC Star

You could add this statement to the beginning of your program:

 

options sasautos = ('C:Project\Study\Test' sasautos);

That would make all macros from that folder (including %grabpath) available to the current program.

 

As you have already done, you would need to name the entries properly.  So grabpath.sas would need to hold the definition of %grabpath.

Kc2
Quartz | Level 8 Kc2
Quartz | Level 8
But if I change the directory name from Test to TestA or TestB, I would need to manually update the program. I would rather not do any manual update.
Astounding
PROC Star

Yes, that's true.  SAS doesn't have a function that says, "I moved my macros somewhere else, so find out where I moved them to."  However, you could just identify a bunch of folders in all your programs if that would work for you:

 

options sasautos=('C:\Project\Study\Test' 'C:\Project\Study\TestA' 'C:\Project\Study\TestB' sasautos);
Quentin
Super User

One alternative is to store general utility macros like this, which will be used across projects, outside of a project-specific directory.  And your code or config or autoexec or start icon or whatever you want can add that fixed location to the autocall search path.  I typically have an autocall search path that starts with a project-specific autocall directory, then the shared utility autocall directory, then SAS-provided locations.

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
Kc2
Quartz | Level 8 Kc2
Quartz | Level 8
Do you have an example?
Quentin
Super User

I have directories like:

C:\Projects\Project1\Code

C:\Projects\Project1\Code\Macros

C:\Projects\Project2\Code

C:\Projects\Project2\Code\Macros

...

C:\Projects\Common\Code

C:\Projects\Common\Code\Macros

 

I put my shared autocall macros in to C:\Projects\Common\Code\Macros.  That's where I would put grabpath.sas, because it's used across projects.

 

On windows, I edit my config file to point to the folder.  Even though the config file says don't edit below this line.  Because I'm a rebel.

 

So my config file has a line like:

-SET SASAUTOS (
        "C:\Projects\Common\Code\Macros"        
        "!SASROOT\core\sasmacro"
        "!SASROOT\graph\sasmacro"
        "!SASROOT\iml\sasmacro"
        "!SASROOT\qc\sasmacro"
        "!SASROOT\stat\sasmacro"
        )

That way every SAS session I start with this config file has my utility autocall library available.

 

Then in a program where the code is stored in a projectN \Code directory, you could call your grabpath macro, and use it to %include your setup code:

%grabpath;

%include "&gpath/setup.sas"  ; 

And assuming setup.sas is just setup-code, it would include a line like below to add the project-specific macro library to the search path:

*add project-specific macro library to front of search path;
options insert=sasautos=("&gpath\Macros") ;

 

 

 

 

 

 

 

 

 

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
Kc2
Quartz | Level 8 Kc2
Quartz | Level 8

thank you this worked.

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!

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
  • 7 replies
  • 889 views
  • 3 likes
  • 3 in conversation