Write and run SAS programs in your web browser

Line breaks in quoted strings export csv

Reply
Occasional Contributor PWS
Occasional Contributor
Posts: 11

Line breaks in quoted strings export csv

[ Edited ]

Hello,

 

I'm trying to find an answer for avoiding line breaks/line feeds in an csv output file.

 

So I want to export a file with multiple columns. One of them is a json string with a lot of qoutes.

 

It looks like this;

 

data _null_ ;
/* FILE "&file_export_wait_s" DLM= ';' ; */
set expclang.&_file_name._export;
FILE "&file_export_wait_s" DLM= ';';

if _n_ = 1 then put @1 'CUSTOMER_ID;SUBJECTLINE;PREHEADER;REFERRER;FLEXBANNERS;GLOBALIDS;TEXTS;CONTENT'; /* Add variable names */
put CUSTOMER_ID SUBJECTLINE PREHEADER REFERRER FLEXBANNERS GLOBALIDS TEXTS CONTENT ;
/* put (_all_) (~);*/

 run ;

The content is a huge string with json in it. What happens in the csv is that there are linebreaks. How can avoid those?

 

Thanks

Super User
Posts: 8,359

Re: Line breaks in quoted strings export csv

[ Edited ]

Try adding a sufficient lrecl= option to your file statement.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor PWS
Occasional Contributor
Posts: 11

Re: Line breaks in quoted strings export csv

Posted in reply to KurtBremser

Thanks! It worked... 

Super User
Posts: 20,735

Re: Line breaks in quoted strings export csv


PWS wrote:

What happens in the csv is that there are linebreaks. How can avoid those?

 

Thanks


What does that mean in detail please? Trying to understand your problem Smiley Happy

Occasional Contributor PWS
Occasional Contributor
Posts: 11

Re: Line breaks in quoted strings export csv

When writing the file to csv a lot of text is written in the file. Especially for content, because there is a json string included, looking like this;

see attached file

 

So one line should start with slgnt19 and the next line should also start with slgnt19.

 

Can't exactly find yet where to put the lrecl= option

 

Super User
Posts: 20,735

Re: Line breaks in quoted strings export csv


PWS wrote:

 

 

Can't exactly find yet where to put the lrecl= option

 


On the FILE statement

http://documentation.sas.com/?docsetId=lestmtsref&docsetTarget=n15o12lpyoe4gfn1y1vcp6xs6966.htm&docs...

Occasional Contributor PWS
Occasional Contributor
Posts: 11

Re: Line breaks in quoted strings export csv

Thanks! It works

Super User
Posts: 20,735

Re: Line breaks in quoted strings export csv

CSV means comma delimited, literally, Comma Separated Values. Why are you using ; as a delimiter if you want a CSV file?

Occasional Contributor PWS
Occasional Contributor
Posts: 11

Re: Line breaks in quoted strings export csv

Good question. For now it's because the receiving party is requesting this delimiter.

Highlighted
Respected Advisor
Posts: 5,052

Re: Line breaks in quoted strings export csv

The delimiter in a CSV file (despite the name) is locale dependent. It is typically the semicolon in French.

PG
Respected Advisor
Posts: 5,052

Re: Line breaks in quoted strings export csv

You could replace all control characters with spaces with something like:

 

TEXTS = prxchange("s/[[:cntrl:]]+/ /o", -1, TEXTS);
PG
Ask a Question
Discussion stats
  • 10 replies
  • 186 views
  • 4 likes
  • 4 in conversation