BookmarkSubscribeRSS Feed
jimbobob
Quartz | Level 8

I found some code that updates some external text files I have that issues with line feeds, and the code fixes the issue, but I have lots of files, is there a way to adapt this to fix multiple files so they can import properly? I tried using the dummy/filevar option with a dataset that has my files listed code that work for one file

	%let repA='@';
	%let repD='$';
data _null_; infile &dsnnme recfm=n sharebuffers; file &dsnnme recfm=n; retain open 0; input a $char1.; if a = '"' then open = ^(open); if open then do; if a = '0D'x then put &repD; else if a = '0A'x then put &repA; end; run;

Tried this but can't get it to work.

	%let repA='@';
	%let repD='$';
	
data _null_;
set WORK.NEW_FILES;
	   location=cats("mnt/ERM/Shared Services/SAS_Datasets/tempfiles/", FILE_NAME);
		infile dummy filevar=location end=done recfm=n sharebuffers;
		file location recfm=n;
do while(not done);  
		retain open 0;
		input a $char1.;
		if a = '"' then open = ^(open);
		if open then do;
			if a = '0D'x then put &repD;
			else if a = '0A'x then put &repA;
		end;
end;
	run;

 

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Don't you want to use option TERMSTR= to read your files instead of rewriting them?

jimbobob
Quartz | Level 8

Thanks Chris, I've tried the termstr=LF as well as cr, crlf and every combo of scanover, truncover etc and it still doesn't read the data in properly, the issue I have is an unexpected LF in the middle of quoted data, so the full line is not read in for the record and instead the rest of the data is read in as another record. Is there another way to deal with issues like this, I would love to not have to rewrite the files. thanks

jimbobob_0-1645635649914.png

 

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
  • 2 replies
  • 536 views
  • 1 like
  • 2 in conversation