BookmarkSubscribeRSS Feed
nathilanga
Calcite | Level 5

Good day 

 

have a list 20 of programs 

Sales.sas

Marketing.sas

HR.sas

 

all these they have a common macro variable called currentReporingmonth i want to iterate through all of them to find and replace that variable with mon1_date9 and output another sas code with chagnes or file for example 

 

Sales.sas -> Sales1.sas

Marketing.sas -> Marketing1.sas

HR.sas -> HR1.sas

 

Your help will be highly appreciated

 

Regards

 

N

 

6 REPLIES 6
AMSAS
SAS Super FREQ

Hi nathilanga,

 

You could write some Base SAS code to do this, but for 20 files, it would probably be simpler to do it manually.

If you are going to be doing this on a regular basis, and want to write some SAS code to do it, then I'd approach it as follows

 

  1. Determine the files to be updated (External File Functions)
  2. Read each file into SAS (Working with External Files)
  3. Do the replace (Character String Matching Functions)
  4. Save each file with a new file name (Working with External Files)

 

nathilanga
Calcite | Level 5
Good day

i am still investigating its some thing that has to do with pipe and xcom in sas
ballardw
Super User

Why change the code? Do you assign a value to the macro variable in each file? If that is the case then a likely better approach would be to remove the assignment code an do that in a separate program that then calls the program files with %include statements.

 

Since you don't actually provide the 1) current macro variable name, 2) how that particular macro variable is used, 3) what you explicitly want the macro variable changed to and 4) source code of at least one of those files, it is very hard to provide any actual concrete code.

 

And things may get more complicated if any of your program files define or call macros.

nathilanga
Calcite | Level 5

Good day

reason for the code change is to standardize it, i have plenty of code that needs to change 

so that everyone can use one auto exec for libraries and dates

andreas_lds
Jade | Level 19

@Kurt_Bremser wrote:

A proper operating system (read: UNIX) provides a great tool for such text operations, it's called awk.


And Windoze has Powershell for the same job but i would use a text-editor allowing find+replace on multiple files in a folder, e.g. Notepad++.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 658 views
  • 0 likes
  • 5 in conversation