DATA Step, Macro, Functions and more

put all records in one line in a flat file

Reply
Frequent Contributor
Posts: 87

put all records in one line in a flat file

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

Respected Advisor
Posts: 4,935

Re: put all records in one line in a flat file

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;
PG
Super User
Posts: 10,046

Re: put all records in one line in a flat file

filename x '/folders/myfolders/x.txt' recfm=n;
proc export data=sashelp.class outfile=x dbms=dlm replace;
delimiter='|';
run;
Ask a Question
Discussion stats
  • 2 replies
  • 221 views
  • 1 like
  • 3 in conversation