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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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