The table results has the correct code-line, but the txt file double or triple quotes when it encounters a double quote.
filename myfldr filesrvc folderPath='/Projects/Portugal/';
data filenames;
length fname $200;
did = dopen('myfldr');
do i = 1 to dnum(did);
fname = dread(did,i);
output;
end;
did = dclose(did);
keep fname;
run;
%let myStr = ; /* string you are looking */
data _null_;
set filenames;
if index(lowcase(fname), '.sas') then
call execute ('
filename search FILESRVC FOLDERPATH="/Projects/Portugal/" FILENAME=' || quote(strip(fname)) || ' ;
data temp;
length file $ 256 code_line $ 2048;
infile search filename = file end=end;
input;
lineNumber+1;
filename = file;
code_line= _infile_;
if find(_infile_, "&myStr.", "i") or length(_infile_) >=1 then output;
if end then lineNumber=0;
run;
proc append base=result data=temp;
run;
');
run;
filename outtxt FILESRVC FOLDERPATH='/Projects/Portugal' FILENAME='_a_sas_code1.txt';
proc sort data=result;
by filename lineNumber;
run;
data _null_;
file outtxt dsd dlm='|' ;
set result ;
by filename;
if first.filename then put filename;
put %NRQUOTE(code_line);
if last.filename then put '0A'x;
run;
The DSD option causes this; since quotes might be used around the string, strings with quotes are also enclosed in quotes, and the quotes in the string are doubled.
You do not need the DSD option and the delimiter, as you only PUT one variable in every line.
The DSD option causes this; since quotes might be used around the string, strings with quotes are also enclosed in quotes, and the quotes in the string are doubled.
You do not need the DSD option and the delimiter, as you only PUT one variable in every line.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.