Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_gsubfile.sas File Reference

Performs a text substitution on a file. More...

Go to the source code of this file.

Detailed Description

Makes use of the GSUB function in LUA to perform a text substitution in a file - either in-place, or writing to a new location. The benefit of using LUA is that the entire file can be loaded into a single variable, thereby side stepping the 32767 character limit in a data step.

Usage:

%let file=%sysfunc(pathname(work))/file.txt;
%let str=replace/me;
%let rep=with/this;
data _null_;
  file "&file";
  put "&str";
run;
%mp_gsubfile(file=&file, patternvar=str, replacevar=rep)
data _null_;
  infile "&file";
  input;
  list;
run;
Parameters
[in]file=(0) The file to perform the substitution on
[in]patternvar=A macro variable containing the Lua pattern to search for. Due to the use of special (magic) characters in Lua patterns, it is safer to pass the NAME of the macro variable containing the string, rather than the value itself.
[in]replacevar=() The name of the macro variable containing the replacement string.
[out]outfile=(0) The file to write the output to. If zero, then the file is overwritten in-place.

SAS Macros

Related Macros

Version
9.4
Author
Allan Bowe

Definition in file mp_gsubfile.sas.