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!
"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;
"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;
Works great, Thank you!
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?
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.