Desktop productivity for business analysts and programmers

Find and replace code in all programs

Posts: 69

Find and replace code in all programs

I need to change a variable name across all programs in a project. I'm going to go ahead and do a CTRL+H find and replace manually, and furthermore, replace it with a macro parameter that I'll add to the macros in which this variable resides (I know that it could have been done in the first place, but it wasn't).

I don't expect there's a better way but I just wanted to ask. I became familiar with Chris Hemedinger's article about searching SAS projects recently, but I do not believe that would allow for replacing text within programs.

Any suggestions for my future edification?

Valued Guide
Posts: 2,111

Re: Find and replace code in all programs

No quick, easy answer.  Technically, you could do it in SAS, but it would be a lot of work.  Depends on how many files....

  1. there are macros on the forums to loop through a series of files (usually Excel, but just change the extension)
  2. read the text in a data step, each line as one long string
  3. use the perl regular expression tools to do the search and replace
  4. write the text back out

Unless you already know how to use perl, 3 might be a challenge.

If you are familiar with Unix scripting, you could download the "GNU on Windows" tools and write the script as a batch file.

Doc Muhlbaier


Trusted Advisor
Posts: 1,517

Re: Find and replace code in all programs

I have done this (not for EG, but just regular SAS, as I don't use EG)

Basically, Doc has the answer, but for his step 3, I just used ordinary SAS code, not Perl regular expressions. The FIND command in SAS is useful for finding lines that have the desired target string, and the SUBSTR command allows you to pull apart the text and make replacements.

Posts: 69

Re: Find and replace code in all programs

Doc & Paige, thanks for those suggestions. The drawback is that (and I didn't make this explicit before) these programs may not be actual physical files-- in an EG project, you can have a program that just lives in the project rather than having a shortcut to a program that lives outside of the project.

Community Manager
Posts: 2,712

Re: Find and replace code in all programs

Unfortunately, there is not a find-and-replace tool that operates across all objects in a project, let alone across several projects.

The EGP Search tool can help you identify the items that you might need to change, but you'll have to open each project and change each manually.


SAS Employee
Posts: 13

Re: Find and replace code in all programs

There is a SAS paper on a macro created with the intention of finding and replacing characters across sas programs. I'm aware you're trying to do this in EG, but maybe reading through it will give you some ideas, or even contacting the author might help. Here you go:
Ask a Question
Discussion stats
  • 5 replies
  • 5 in conversation