SAS Programming

DATA Step, Macro, Functions and more
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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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