BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
acordes
Rhodochrosite | Level 12

The table results has the correct code-line, but the txt file double or triple quotes when it encounters a double quote.

 

pic.png

 

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;

pic1.png

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 751 views
  • 2 likes
  • 2 in conversation