Hi,
since SAS file are basic text files, I would perform the replacements directly from SAS and reserve powershell for more complex tasks.
This is how you could achieve what you want
%MACRO replaceCodeLine();
%*Define here your replacement strategy;
%*codeLine is one line of code in the current SAS program beeing read;
if index(codeLine,'I have three books') then codeLine=tranwrd(codeLine,'I have three books','I need coffee');
else if index(codeLine,'I am going to office') then codeLine=tranwrd(codeLine,'I am going to office','I will be dancing');
%*You could use regex as well depending on your replacement needs;
%MEND replaceCodeLine;
%MACRO proceedCurrentSasPgm(fullpath=);
%*Performs replacement for the current SAS file;
FILENAME saspgm "&fullpath.";
DATA _CurrentSasPgmDS;
*Read each line of code;
infile saspgm dsd truncover;
input codeLine $32767.;
RUN;
DATA _NULL_;
SET _CurrentSasPgmDS;
*Perform replacement;
%replaceCodeLine();
file saspgm;
*write out to file;
put codeLine;
RUN;
*Clean up;
PROC DATASETS lib=work nolist; delete _CurrentSasPgmDS; RUN;QUIT;
filename saspgm clear;
%MEND proceedCurrentSasPgm;
*Get list of *.sas files in directory and subdirectories;
%let filepath=C:\Temp\test\*.sas;
filename tmp pipe "dir /b /s /a:-D ""&filepath."" 2>&1";
DATA _NULL_;
infile tmp dlm="¬";
length Fullpath $2000;
input Fullpath;
*Loop through the list of SAS files and perform replacements in each one;
call execute('%nrstr(%proceedCurrentSasPgm(fullpath='||strip(fullPath)||'));');
RUN;
filename tmp clear;
... View more