SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Taliah
Quartz | Level 8

Hello,

I'm writing a text file using the following code

filename out "file_name.txt";

data _null_;

     set dataA end=eof;

     file out;

    outline= cats(var1, var2, var3,'09'x);

     put outline;

     if eof then put "last_line_txt.";

run;

 

I get a text file where at the end of each line there are CR LF LF

(created by the '09'x)

I need only CR LF (without the second LF)

How do I do that?

I tried 'ODOA'x instead of the '09'x, but that does not work.

Thank you!

 

1 ACCEPTED SOLUTION

Accepted Solutions
3 REPLIES 3
Kurt_Bremser
Super User

"09"x is a tab, not a LF. LF is "0A"x.

To manipulate the end-of-line, use the TERMSTR option:

file out termstr=CRLF;
outline= cats(var1, var2, var3);
put outline;
Taliah
Quartz | Level 8

Works great, Thank you!

Tom
Super User Tom
Super User

If you want full control use the RECFM=N option on the FILE statement.

data _null_;
     set dataA end=eof;
     file out recfm=n ;
     outline= cats(var1, var2, var3,'0D0A'x);
     put outline;
     if eof then put "last_line_txt.";
run;

Is there some reason why you need to make the writing of a text file so complicated?

Why are you not writing the end of line characters on the last line of the file?

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
  • 1514 views
  • 0 likes
  • 3 in conversation