Hi, I have a dataset that contains multiple records. I need to write it out to a flat file in such a way that all records are written in first record. (same row as header). Below is the code I wrote. But, my job is truncating the file and not outputting all records as I need.
filename credit "/user/ccc/xx/LTR.txt";
data _null_;
set test;
file credit dlm="|" dsd lrecl=60000;
if _n_=1 then do;
put @1'var1|var2|var3|var4|var5|var6|var7'
var1 var2 var3 var4 var5 var6 var7;
end;
run;
NOTE: 1 record was written to the file CREDIT.
The minimum record length was 90.
The maximum record length was 90.
NOTE: There were 7 observations read from the data set WORK.TEST.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
user cpu time 0.00 seconds
system cpu time 0.01 seconds
Memory 1075k
OS Memory 13352k
Timestamp 1/11/2016 10:41:44 PM
Page Faults 0
Page Reclaims 548
Page Swaps 0
Voluntary Context Switches 19
Try something like :
filename credit "&sasforum.\datasets\credit.txt";
data _null_;
file credit lrecl=60000;
put 'name|sex|age|height|weight|' @;
do while(not done);
set sashelp.class end=done;
put (name sex age height weight) (+(-1)"|") @;
end;
stop;
run;
filename x '/folders/myfolders/x.txt' recfm=n;
proc export data=sashelp.class outfile=x dbms=dlm replace;
delimiter='|';
run;
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 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.