Hi,
I'm having arround 50 sas codes. in which %include (%include path/aaa.sas) statment should be added at the beginning of the sas code, for all 50 sas codes.
can I have a macro to Insert % include statment into the sas codes.
apprectite help!
Thanks.
I would recommend make NEW files with the changes. You can then QC the changes before replacing the OLD files with the new files.
Say the original files are in a directory named DIR1 and you have an empty directory named DIR2 where you can write the updated programs. And if you want to update ALL of the .sas file in DIR1 then you should be able to do it with a simple data step.
data _null_;
length fname1 fname2 $200 ;
infile 'c:\downloads\dir1\*.sas' filename=fname1;
input ;
fname2 = tranwrd(fname1,'c:\downloads\dir1\','c:\downloads\dir2\');
file out filevar=fname2;
if fname1 ne lag(fname1) then put '%include "path/aaa.sas";' ;
put _infile_;
run;
If you are asking for code to insert one line of code into existing SAS program files it is likely to be just as quick to open each and paste the text and save the file. With none of the possible problems of overwriting or accidentally modifying code. For one thing, you should make a back up of every single one of those file before starting or testing any such code just in case.
I would ask for a description of what that include code is supposed to do though. If that many different programs need it then perhaps there is a more robust way to use that file.
For example if the %include file contains only macro definitions then add the macro code that would be called to a location and add that location to the Autocall in your SAS Autoexec.
I would recommend make NEW files with the changes. You can then QC the changes before replacing the OLD files with the new files.
Say the original files are in a directory named DIR1 and you have an empty directory named DIR2 where you can write the updated programs. And if you want to update ALL of the .sas file in DIR1 then you should be able to do it with a simple data step.
data _null_;
length fname1 fname2 $200 ;
infile 'c:\downloads\dir1\*.sas' filename=fname1;
input ;
fname2 = tranwrd(fname1,'c:\downloads\dir1\','c:\downloads\dir2\');
file out filevar=fname2;
if fname1 ne lag(fname1) then put '%include "path/aaa.sas";' ;
put _infile_;
run;
it worked fine, Apreciate it.
need one more help in same way after adding '%include "path/aaa.sas";'
can we change 'USER="&userid" ORAPW="&pswd"' to "abcd=xyz" in same code
it makes job compete.
Thanks.
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: