%let macrodir=\\133.3.3.3\a\a\DataPre\Macro;
%include "¯odir\allmacros.sas";
I wrote the above ,trying to include all macros under the directory, but failed.
How to modifiy those code?
Thanks.
Editor's note: SASAUTOS is probably the best solution here since the macro will only be compiled if invoked. SASAUTOS does the %INCLUDE for you behind the scene when called. To add to the soution below I would make one modification to the option, for example:
options sasautos=(sasautos,"¯odir");
By adding SASAUTOS in the search path we include the SAS supplied autocall macros. Without adding this you will be overwriting what SASAUTOS is pointing to and you will not have access to the SAS supplied autocall macros.
It's possible you found a way by now, but consider that it might not be the correct thing to do. If you want all the macros in the folder available for use, you don't have to %include them. Another approach:
options sasautos=("¯odir.");
You can also specify more than one folder using this method.
Good luck.
Nothing wrong with your code.
Run the command
filepad "\\133.3.3.3\a\a\DataPre\Macro\allmacros.sas" to check the file is there.
filepad "\\133.3.3.3\a\a\DataPre\Macro\allmacros.sas";
filepad was red
log is somewhat like invalid statement or not using in correct sequence.
(SAS version not an english version)
Hi,
Try this...F$ is the drive...
%let macrodir=\\133.3.3.3\f$\SASCodes;
%include "¯odir\Import.sas";
Thanks,
Shiva
this is a command, not a statement.
run from the command box.
filename mymacs "¯odir";
%include mymacs('*.sas');
Elegant and to the point. Will make it easy for my purposes. With larger projects, I like to have several .sas files with specific purposes. Any idea on whether this would cause additional .sas files in subfolders to be included?
That syntax would no include files from subdirectories.
Editor's note: SASAUTOS is probably the best solution here since the macro will only be compiled if invoked. SASAUTOS does the %INCLUDE for you behind the scene when called. To add to the soution below I would make one modification to the option, for example:
options sasautos=(sasautos,"¯odir");
By adding SASAUTOS in the search path we include the SAS supplied autocall macros. Without adding this you will be overwriting what SASAUTOS is pointing to and you will not have access to the SAS supplied autocall macros.
It's possible you found a way by now, but consider that it might not be the correct thing to do. If you want all the macros in the folder available for use, you don't have to %include them. Another approach:
options sasautos=("¯odir.");
You can also specify more than one folder using this method.
Good luck.
The problem with the sasautos option is that it must be invoked when SAS is started. This means that a user who does not include the option when they start SAS must find some other way to compile the macros. It can be very confusing if you are trying to debug someone else's program that works perfectly for them because their code may not include any reference to where the macros are located.
So I would only advocate use of sasautos under very tight controls where all users have it activated and the directories are read only (because one user's mod of a macro would require integration testing of all other SAS code which might make use of the macro).
Richard
RichardinOz,
I'm not sure which method would be simpler. I could imagine a user of either method being dumbfounded by being asked where his macro is stored. In fact, I've even seen one experienced programmer who stored 40 macros in a single file so he could %include just that one file. If you're going to %include all of your macro definitions, that makes as much sense as any.
Note that sasautos doesn't have to be specified at SAS invocation. The options statement can appear within a SAS program.
Astounding
Aha, that change to sasautos system option snuck up on me. Makes it more usable.
I still prefer individual %include statements for each macro file, because that states explicitly at th head of a script, where each macro is located.
Richard
I have had many discussions with other SAS-L peers over the years about this idea of
%including user-written macros before they are called.
summary:
keep the log short: do not %include
SAS does the %include for you via the option sasautos.
commentary: isn't mprint enough for you to see the code generated?
Ron Fehd SASautos maven
http://www.sascommunity.org/wiki/SASautos_Companion_Reusing_Macros
May be this can be useful for your task... Its a bit complicated but can be used as a macro application.
Assuming your single folder have all program that you want to call using %include....
Here is the program
Note: This macro take the full name of all file in a folder ending with .sas .
Create a series of macro variable with file name .
Resolve the value of each SAS file in %include statement using %do loop in macro.
%macro test(dir=);
filename filelist pipe "dir /b /s &dir\*.sas";
data _null_;
infile filelist truncover end=last;
input filename $100.;
call symputx('mac1'||left(_n_) , strip(filename));
if last then call symputx('nobs' , _n_);
run;
%do i =1 %to &nobs;
%include "&&mac&i";
%end;
%mend test;
Hope it will help.....
%test(dir=\\133.3.3.3\a\a\DataPre\Macro)
More simple program may be...
%macro findsas(path);
filename filelist pipe "dir /b /s &path\*.sas";
data _null_;
infile filelist truncover;
input filename $100.;
call execute(cats('%include ',quote(trim(filename)), ';'));
run;
%mend findsas;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.