BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jimbo2
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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;
ballardw
Super User

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?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 926 views
  • 0 likes
  • 3 in conversation