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

I have to run three macros; each defined by extensive pieces of code (filename1, filename2, filename3). Rather than creating one large file with everything (which makes it extremely difficult to debug), I was wandering if I could use the %include statement in a seperate macros to run my other three macros one after the other. I have the following code; could someone with more exprience with the %include statement please provide a sanity check, because this doesn't seem to be running.

%macro MainMacro;

      %include '\filepathmaindirectory\filepathsubdirectory\filename1';

      %include '\filepathmaindirectory\filepathsubdirectory\filename2';

      %include '\filepathmaindirectory\filepathsubdirectory\filename3';

%mend MainMacro;

%MainMacro;

Any suggestions would be helpful.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Sounds like you are talking about programs and not macros.  If you were talking about macros then your syntax would look more like:

* Define the macro;

%include '\filepathmaindirectory\filepathsubdirectory\filename1';

* Call the macro ;

%filename1(option1=yes,option2=no);

If you create your files in this way then you can use SASAUTOS.

options insert=(sasautos='\filepathmaindirectory\filepathsubdirectory') mrecall ;

%filename1(option1=yes,option2=no);

%filename2;

%filename3;

View solution in original post

3 REPLIES 3
Reeza
Super User

You don't need macros, can use %include directly, though I've always seen it include the .sas extension.

Something like the following should work:

      %include '\filepathmaindirectory\filepathsubdirectory\filename1.sas';

      %include '\filepathmaindirectory\filepathsubdirectory\filename2.sas';

      %include '\filepathmaindirectory\filepathsubdirectory\filename3.sas';

Tom
Super User Tom
Super User

Sounds like you are talking about programs and not macros.  If you were talking about macros then your syntax would look more like:

* Define the macro;

%include '\filepathmaindirectory\filepathsubdirectory\filename1';

* Call the macro ;

%filename1(option1=yes,option2=no);

If you create your files in this way then you can use SASAUTOS.

options insert=(sasautos='\filepathmaindirectory\filepathsubdirectory') mrecall ;

%filename1(option1=yes,option2=no);

%filename2;

%filename3;

Tom
Super User Tom
Super User

You can specify more than one filename in the %INCLUDE statement.

filename myprogs '\filepathmaindirectory\filepathsubdirectory\';

%inc myprogs(filename1 filename2 filename3) / source2;

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