DATA Step, Macro, Functions and more

Writing a Macro program to write or update a .sas file

Reply
Senior User
Posts: 1

Writing a Macro program to write or update a .sas file

Hi Guys,

 

I would like to ask for your help to determine if my idea is possible. I am currently automating a group of .sas program and currently finished writing a macro code that creates a table log or statistics that will send and email. Let's call the macro %etl_begin and %etl_end, this macro should be put on pre and post process part. I need to put this %macros in precode and post code of each .sas file without opening and pasting the macro on the code. Any idea how can I do this? Any time my .sas file increments so i'm thinking I would use a x command line to list all the .sas file on a specific folder.

 

 

Thanks.

Super User
Posts: 19,855

Re: Writing a Macro program to write or update a .sas file

.sas files are text files. If your code goes right at beginning and end basic line commands to append the text files should suffice. Look at the command line function called CAT. 

 

https://en.m.wikipedia.org/wiki/Cat_(Unix)

Super User
Posts: 7,840

Re: Writing a Macro program to write or update a .sas file

Also use grep first to determine if the macro calls are already present.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 11,343

Re: Writing a Macro program to write or update a .sas file

I am not sure if this addresses your situation but if you mean that you want to execute some code before executing another SAS program file perhaps you want a control SAS program that includes the other programs. Then you could place the macro calls before/after the include. The control program would look something like:

 

%etl_begin ;

%include "path/SASProgram1.SAS";

%etl_end;

 

%etl_begin ;

%include "path/SASProgram2.SAS";

%etl_end;

 

%etl_begin ;

%include "path/SASProgram3.SAS";

%etl_end;

 

If you have not used %include all it does is in effect read an external progam file into the current program.

Ask a Question
Discussion stats
  • 3 replies
  • 117 views
  • 0 likes
  • 4 in conversation