I want to export a wide SAS dataset (a few thousand columns and a few hundred thousand rows) to a text file.
proc contents data=myData out=contents(keep=name) noprint; run; proc sql noprint; select name into :header separated by '|' from contents; quit; %put NOTE: &=header; data _null_; file 'G:\myPath\output.txt' lrecl=500000 dsd dlm='|'; set myData; IF _N_=1 THEN PUT "%BQUOTE(&header)"; put (_all_)(+0); run;
This would work in theory, however, my header is over 32,767 characters long and is truncated. How can I modify these statements to ensure the whole header is written to the output file?
This is on SAS 9.4.
By not using macro variables.
proc contents data=myData
out=contents(keep=name varnum)
noprint;
run;
proc sort data=contents;
by varnum;
run;
data _null_;
file 'G:\myPath\output.txt' lrecl=500000 dsd dlm='|';
set contents end=eof;
put name @ ;
if eof then put;
run;
data _null_;
file 'G:\myPath\output.txt' lrecl=500000 dsd dlm='|' mod;
set myData;
put (_all_)(+0);
run;
By not using macro variables.
proc contents data=myData
out=contents(keep=name varnum)
noprint;
run;
proc sort data=contents;
by varnum;
run;
data _null_;
file 'G:\myPath\output.txt' lrecl=500000 dsd dlm='|';
set contents end=eof;
put name @ ;
if eof then put;
run;
data _null_;
file 'G:\myPath\output.txt' lrecl=500000 dsd dlm='|' mod;
set myData;
put (_all_)(+0);
run;
You may need to share which SAS system you are operating under.
It may be worth trying a FILENAME statement to create a file reference instead of using the file statement in the data step to set properties. No promise.
And did you try Proc Export by any chance?
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.