BookmarkSubscribeRSS Feed
rykwong
Quartz | Level 8

Hello SAS community, 

I have a dataset of N=107 and I use 

proc export data=Apollo_final
dbms=csv outfile='apollo.csv'
replace;
delimiter = "|";
run;

but 2 of the observations broke from this

rykwong_0-1722522575138.png

 

into this in the CSV output.  Any help?

rykwong_1-1722522651939.png

 

2 REPLIES 2
Tom
Super User Tom
Super User

It is really hard to tell from PHOTOGRAPHS of text what you mean.  

 

Let's assume you mean that the CSV file has more LINES than the number of OBSERVATIONS that existed in the SAS dataset.

 

There are two issues that will cause the generated CSV file to appear to have more lines.  Some of the text values have embedded end-of-line characters in them.  The lines being written were too long and so SAS wrapped to the next line to finish writing the observation.

 

For the second problem make sure that the LRECL used when writing the text file is large enough to hold the longest possible line.

 

For the first problem you should clean the data and remove (or replace) any CR and/or LF characters in the data.  If you tell SAS to write the text file using CR+LF as the end-of-line marker then you can leave in the LF and CR characters as long are they are no CR+LF pairs.

filename csv 'apollo.csv' lrecl=1000000 termstr=crlf;

data for_export;
  set apollo_final;
  array _char_ _character_;
  do over _char_;
     _char_ = tranwrd(_char_,'0D0A'x,'0D'x);
  end;
run;

proc export data=for_export dbms=csv outfile=csv ;
  delimiter = "|";
run;
rykwong
Quartz | Level 8
Sorry for the screenshot
I will try your suggestion. Many thanks

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 16. 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
  • 263 views
  • 1 like
  • 2 in conversation