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

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.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

5 REPLIES 5
ballardw
Super User

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.

fja
Lapis Lazuli | Level 10 fja
Lapis Lazuli | Level 10
If you have access to the underlying OS ... i.e. an account on that machine running SAS ... AND this is UNIX based i'd suggest using sed ...
Tom
Super User Tom
Super User

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;
Asbon
Obsidian | Level 7

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.

 

Asbon
Obsidian | Level 7
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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 5 replies
  • 714 views
  • 2 likes
  • 4 in conversation