hi,
i am generating .txt file with following code
example
Data test;
input name $1-1 age $ 3-5 sex $ 6-7;
cards;
a m
b 14 m
c 15 m
d 8 f
e f
;
run;
data newtest;
file "path.txt";
if missing(age) then do;
want = catt(name,'|',age,' |',sex);
put @1 want;
end;
else do;
want=catt('|',name,age,sex);
put want;
end;
run;
i need to stop cursor i last observation of last column but
in text file after last row cursor is moving to next line(one blank space)
wright now iam placing cursor at last obs and using delete key
this .txt file is entering in software
it is not accepting if blank space is comming
is there any way to stop cursor at last obs after completing of data
Much easier to just use a macro like %sas2csv.
SAS-macros/sas2csv2.sas at master · friendly/SAS-macros · GitHub
Doc Muhlbaier
Duke
You need recfm= option to change the format of recod into fixed format.
filename x 'c:\x.txt'; Data test; input name $1-1 age $ 3-5 sex $ 6-7; cards; a m b 14 m c 15 m d 8 f e f ; run; data newtest; set test; file x recfm=f; if missing(age) then do; want = catt(name,'|',age,' |',sex); put @1 want; end; else do; want=catt('|',name,age,sex); put want; end; run;
Ksharp
Hi Kshap,
Thanks for your support
i am getting output but only missing values in text
a| |m b|14|m c|15|m d|8|f
e| |f
i want output as
a| |m
b|14|m
c|15|m
d|t8|f
e| |f
Sorry. I can't help you. Maybe you can talk to Technique Support.
Hi
How about using the DLM= option of the FILE statement
Use the CAT function in stead of CATT (TRIM) or CATX (TRIM(LEFT))
DATA test;
INPUT name $1-1 age $ 3-4 sex $ 6-6;
CARDS;
a m
b 14 m
c 15 m
d 8 f
e f
;
RUN;
/*
Function Equivalent Code
CAT(OF X1-X4) X1||X2||X3||X4
CATS(OF X1-X4) TRIM(LEFT(X1))||TRIM(LEFT(X2))||TRIM(LEFT(X3))||TRIM(LEFT(X4))
CATT(OF X1-X4) TRIM(X1)||TRIM(X2)||TRIM(X3)||TRIM(X4)
CATX(SP, OF X1-X4) TRIM(LEFT(X1))||SP||TRIM(LEFT(X2))||SP||TRIM(LEFT(X3))||SP||TRIM(LEFT(X4))
*/
DATA _NULL_;
SET test;
FILE LOG;
want = CAT (name, '|', age, '|', sex);
PUT @1 want;
RUN;
/*
a| |m
b|14|m
c|15|m
d|8 |f
e| |f
*/
Sounds like you are saying that you want to generate a text file where the end of line character at the end of the last line does not exist? If so and your program does not except that input it seems strange to me as that is the reverse of what most programs want. I have had many programs complain when the last line does NOT have and end of line character.
It is really hard to get SAS to not write that final end of line. You could try writing ASCII code 26 ( '1A'x) at the end of the last line. This won't stop SAS from also writing the end of line after it, but perhaps the other program will truncate input when it sees it.
data _null_;
file 'out.txt' ... ;
set have end=eof;
put .... @;
if eof then put '1A'x @;
else put;
run;
HaHa, I found a way.
data _null_; file 'c:\x.txt' recfm=f ; set sashelp.class; length a $ 256; a=cats(_n_,of _all_); put a $800.; run;
Ksharp
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.