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?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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