I have created a small code but I don't understand why it is not working.
%macro sn;
filename x 'C:\SAS\SAS9.1\dquality\sample\*.sas';
CALL EXECUTE (' %INCLUDE "&x"; ');
%mend sn;
%sn;
Error:1 CALL Execute('%INCLUDE "C:\SAS\SAS9.1\dquality\sample\dqanalyz.sas";');
----
180
MPRINT(SN): CALL Execute('%INCLUDE "C:\SAS\SAS9.1\dquality\sample\dqanalyz.sas";');
ERROR 180-322: Statement is not valid or it is used out of proper order.
MLOGIC(SN): Ending execution.
You defined a fileref named X and then later tried to use a macro variable named X that you never defined.
You cannot use CALL EXECUTE() outside of a DATA step. Your program does appear to need a data step. It also doesn't need to be wrapped in a macro definition either.
Instead just use the fileref in the %INCLUDE statement.
filename x 'C:\SAS\SAS9.1\dquality\sample\*.sas';
%INCLUDE X ;
Or skip the FILENAME and use the path in the %INCLUDE statement.
%INCLUDE 'C:\SAS\SAS9.1\dquality\sample\*.sas';
You could also point the fileref at the folder.
filename x 'C:\SAS\SAS9.1\dquality\sample\';
%INCLUDE X('*.sas');
But watch out if you are using Windows because of how it handles extensions longer than three characters. The pattern *.sas will also match *.sas7bdat and *.sas7bcat.
%let X = %STR('C:\SAS\SAS9.1\dquality\sample\*.sas');
%macro sn;
CALL EXECUTE (' %INCLUDE "&x"; ');
%mend sn;
%sn;
Try taking the filename out of the macro and making it a %LET as shown.
And %sn needs to be inside a Data step, like so:
DATA _NULL_;
%sn;
RUN;
Jim
First make sure you moved %sn inside a DATA step.
Then, please post your code and your log using the buttons in the reply window.
Jim
Oh, wait. I see the problem. You have an asterisk in your "X". You can't do that.
Let me code something up.
Jim
OK, try this code (below). CAUTION: This code will execute every program in the folder you point to. You are going to run every program in that directory if you use this code.
You need to double check that I've set the Path and the Drive correctly.
Jim
%LET Path = C:\SAS\SAS9.1\dquality\sample;
%LET Drive = C;
FILENAME Pgm_List PIPE "cd ""&Path"" && &Drive: && dir *.sas /a /b";
DATA _NULL_;
INFILE Pgm_List;
INPUT Pgm_Name : $256.;
Pgm_Name = CATS("&Path", "\", Pgm_Name);
PUTLOG "NOTE: " Pgm_Name=;
CALL EXECUTE (CATX(' ', '%INCLUDE"', Pgm_Name, '";'));
RUN;
@Reeza wrote:
What are you trying to do here?
Wouldn't the following do what you want? Why the need for the CALL EXECUTE?
%include 'C:\SAS\SAS9.1\dquality\sample.*.sas';
Would that work with a wildcard like that?
I would agree that a CALL EXECUTE isn't strictly necessary here. I have used CALL EXECUTE to format the commands for a SYSTASK to launch a bunch of SAS jobs that each write their own log and essentially function as independent jobs once launched. I've found that to be useful.
Jim
Oh, fantastic. I've used a wildcard on a Filename before but never an Include. Thank you for that. Perhaps it will come in handy some day.
Jim
You defined a fileref named X and then later tried to use a macro variable named X that you never defined.
You cannot use CALL EXECUTE() outside of a DATA step. Your program does appear to need a data step. It also doesn't need to be wrapped in a macro definition either.
Instead just use the fileref in the %INCLUDE statement.
filename x 'C:\SAS\SAS9.1\dquality\sample\*.sas';
%INCLUDE X ;
Or skip the FILENAME and use the path in the %INCLUDE statement.
%INCLUDE 'C:\SAS\SAS9.1\dquality\sample\*.sas';
You could also point the fileref at the folder.
filename x 'C:\SAS\SAS9.1\dquality\sample\';
%INCLUDE X('*.sas');
But watch out if you are using Windows because of how it handles extensions longer than three characters. The pattern *.sas will also match *.sas7bdat and *.sas7bcat.
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!
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.