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

Hi I have two questions

1. How to call all macros into the session  at a time.

Example: I have a folder  called 'Macros' that has Two Macros  ( see image )

Path of Folder location : "V:\xx6\syy\381\analysis\"

So How to call all the macros (2 ) from folder. I tried this but no luck Please let me know if  I am doing wrong!

options sasautos= ('V:\xx6\syy\381\analysis\Macros', sasautos);

SASuserlot_0-1645218452367.png

2. My second question is  when create macros, the program name has to be the same as macro name? so that sasautos options work.

Example: my   macro program  name is 'chkvar.sas"  but macro name is '%bign' in the program .

 

Thanks you for your inputs.

 

 

1 ACCEPTED SOLUTION
7 REPLIES 7
ballardw
Super User

All the SASAUTOS option does is assign places for SAS to look when code references a macro that has not been defined (macro code executed to compile the macro) in the current session.

 

Yes, the file name must be the name of the macro and the first non-comment  line of the file has to have the %macro statement.

 

You use the  macros with code in programs you are executing.

 

If you want to keep the file names you want then you would not use the SASAUTOS so much as program file that %includes all of the macro code and have that program, or the %include statements, execute from the Autoexec.sas.

 

A statement like:

 

%include("C:\folder\subfolder\nameoffile.sas");

will submit the code in that file to current session when encountered. You should have one %include statement for each file you want to execute. You may get away with wildcards but results may be inconsistent.

Reeza
Super User
1. Use %INCLUDE with a * wild card.
%include 'V:\xx6\syy\381\analysis\Macros\*.sas' / source2;

2. If you want to use SAS autos then yes.

SASAUTOS makes macros available, not sure it actually runs them so your use case seems slightly different than the intended usage? If you want to run all these every time you start SAS you want to add that %INCLUDE line to your AUTOEXEC instead.

SASuserlot
Barite | Level 11

Thanks @Reeza . Please see my responses in blue.

1. Use %INCLUDE with a * wild card.
%include 'V:\xx6\syy\381\analysis\Macros\*.sas' / source2;
Response: This way I have to write 20 times with %include statement if I have 20 macro programs in the folder?


2. If you want to use SAS autos then yes.

Response: Interesting, for some reason I tried again moving programs into different folder. It was able to run the macro even though my program name different than macro name. 
SASAUTOS makes macros available, not sure it actually runs them so your use case seems slightly different than the intended usage? If you want to run all these every time you start SAS you want to add that %INCLUDE line to your AUTOEXEC instead.

Reeza
Super User

@SASuserlot wrote:

Thanks @Reeza . Please see my responses in blue.

1. Use %INCLUDE with a * wild card.
%include 'V:\xx6\syy\381\analysis\Macros\*.sas' / source2;
Response: This way I have to write 20 times with %include statement if I have 20 macro programs in the folder?

The * wildcare will run ALL programs in the folder that ends in .sas, in the order they appear which varies slightly by system. If the order matters then you should call them manually. 


2. If you want to use SAS autos then yes.

Response: Interesting, for some reason I tried again moving programs into different folder. It was able to run the macro even though my program name different than macro name. 


SASAUTOS makes macros available, not sure it actually runs them so your use case seems slightly different than the intended usage? If you want to run all these every time you start SAS you want to add that %INCLUDE line to your AUTOEXEC instead.


That is correct. If you want use SASAUTOS then the file name must match the macro name. Simplified version of SASAUTOS, you invoke a macro, %test. It looks in that folder, in the order of folders you've declared for the test file to compile that macro. This means you can call the macro without explicilty calling the source macro code. 

 

However, that's not what you're trying to do, so you're using the wrong tool in this case, SASAUTOS when it seems you want these run, ie executed. 

SASAUTOS makes macros available for you, but doesn't actually run them. 

 

 

 

 

SASuserlot
Barite | Level 11

Thank you.

SASuserlot
Barite | Level 11

Thank you. @Kurt_Bremser @Reeza @ballardw  thank you guys. all your inputs are right.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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