Hi,
I'm having trouble with my output (Text) file.
Here's my code:
data null;
file &file3 linesize=3200 dlm='|' ;
set USDATM_&MTH. end=eof;
if _n_= 1 then do;
put
'ATM_ID'
'|ATM_ALT_ID'
'|ATM_USD_CSH_IND'
;
end;
put
atm_id
atm_alt_id
atm_usd_csh_ind
;
if eof and char in ('0D'x, '0A'x) then
put @;
run;
My output looks like this:
VAR1|VAR2|VAR3
ABC5|FD53|Y
DEF0|FE78|Y
FDS9|EW38|Y
FDR4|QW82|Y
I want to remove the extra line at the bottom..
Please help.
thanks
OK. How about this one ?
data _null_;
set sashelp.class end=last;
file '/folders/myfolders/want.txt' recfm=n;
if _n_=1 then put "Name|sex|age|weight" '0D0A'x;
put name +(-1)'|' sex +(-1)'|' age +(-1)'|' weight ;
if not last then put +(-1) '0D0A'x;
run;
Why not take out the statement
if eof and char in ('0D'x, '0A'x) then
put @;
Here is an example. Is this file for windows or for unix ?
Windows use '0D0A'x
Unix use '0A'x
data _null_;
set sashelp.class end=last;
file '/folders/myfolders/want.txt' recfm=n ;
put name +(-1)'|' sex +(-1)'|' age +(-1)'|' weight @;
if not last then put '0D0A'x;
run;
OK. Try this one .
data _null_;
set sashelp.class end=last;
file '/folders/myfolders/want.txt' recfm=n dlm='|';
if _n_=1 then put "Name|sex|age|weight" '0D0A'x;
put name sex age weight ;
if not last then put '0D0A'x;
run;
OK. How about this one ?
data _null_;
set sashelp.class end=last;
file '/folders/myfolders/want.txt' recfm=n;
if _n_=1 then put "Name|sex|age|weight" '0D0A'x;
put name +(-1)'|' sex +(-1)'|' age +(-1)'|' weight ;
if not last then put +(-1) '0D0A'x;
run;
OK. This is really not easy. This code ought to be right.
data _null_;
set sashelp.class end=last;
file '/folders/myfolders/want.txt' recfm=n;
if _n_=1 then put "Name|sex|age|weight" '0D0A'x;
length x $ 4000;
x=catx('|',name,sex,age,weight);
len=length(x);
put x $varying4000. len ;
if not last then put '0D0A'x;
run;
You may want to look at the TERMSTR option on your FILE statement. It sets whether the end of line is CRLF (windows default) LF or NL
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.