SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
jmmedina25
Obsidian | Level 7

For some reason, my data keeps exporting with a LR end line character instead of a CR LF end line character.  I have no idea if this can be fixed during the output in SAS but if it can that'd be great.  

 

Here's how my data looks:

Memberid  level
xxx1 2
xxx2 2
xxx3 2
xxx4 2
xxx5 2
 

 

And this is the code I'm using to export this data:

 

PROC EXPORT DATA= work.new_data
outfile= "/windows/data_011420_0312.txt"
dbms = DLM replace;
delimiter="|";
run;

3 REPLIES 3
Tom
Super User Tom
Super User

If you are running SAS on Unix then the default will be to use linefeed ('0A'x) as the end of line character.  If you are running on Windows then the default will be CRLF ('0D0A'x) instead.  You can use the TERMSTR= option on the FILENAME or FILE statement to control that.

 

To write a delimited text file a DATA step with appropriate FILE and PUT statements is about all you need. 

 

But if you do feel a need to use PROC EXPORT instead then you will need add a FILENAME statement to define a fileref.  You will then reference the fileref in the PROC EXPORT statement instead of the raw physical filename. That way you have a place to put the TERMSTR= option.

 

filename out "/windows/data_011420_0312.txt" termstr=crlf ;
PROC EXPORT DATA= work.new_data
  outfile= out replace
  dbms = DLM 
;
  delimiter="|";
run;

 

 

 

jhur514
Calcite | Level 5

Hello, 

Your comment was helpful in getting my file encoded with windows CRLF, but i'm noticing that it is causing many of the variables in my file to get dropped/removed. The code I use is exactly as you show, but also using encoding= 'UTF-8' and options nobomfile as I need the file to be encoded in utf-8. Happy to share more info if needed. 

Wondering if you've run into this issue and have a potential fix. Thank you! 

Tom
Super User Tom
Super User

Please start a NEW question instead of posting on a two year old thread.  You can include a link to this if you want.

 

Include the actual code you ran, any notes or errors from the SAS log.

 

Is the problem that you values are too long for the default 32K record length?  If so then add the LRECL= option to the FILENAME statement to set something longer.  In general you can have any length then , but memory limits on particular operating systems might limit you to 10000000 bytes max for LRECL setting. Which should be way longer than any reasonable dataset would require.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 3 replies
  • 9255 views
  • 3 likes
  • 3 in conversation