10

I have been trying to export a SAS data set with 49 variables. Each of these variables can potentially be 32767 characters long. I want to write this data set to a txt file, but SAS limits me with the lrecl option at 32767 characters. Is there a way to do this? I tried using the data step.

data _null_;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
%let _EFIREC_ = 0;     /* clear export record count macro variable */
file 'C:path\TEST.txt';
if _n_ = 1 then do;
   put "<BLAH>"
   ;
end;
set  WORK.SAS_DATASET   end=EFIEOD;
   format raw1 $32767. ;
   format raw2 $32767. ;

   etc...
 do;
   EFIOUT + 1;
   put raw1 $ @;
   put raw2 $ @;

   etc...
   ;
 end;
if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
if EFIEOD then
 do;
   put "</BLAH>"
   ;
   call symputx('_EFIREC_',EFIOUT);
 end;
run;
Mark Nielsen
  • 991
  • 2
  • 10
  • 28

1 Answers1

6

Sure. You just need to specify the LRECL yourself.

filename test temp;
data _null_;
set sashelp.class;
file test lrecl=999999;
put
@1 name $32767.
@32768 sex $32767.
@65535 age 8.
;;;;
run;

Some OSs might limit your logical record length, but it's at least 1e6 in Windows so you should be okay.

Joe
  • 62,789
  • 6
  • 49
  • 67
  • Awesome... I made the mistake of defining it prior to my data step using the `options lrecl=10000000;` statement which gave me an error. – Mark Nielsen Apr 09 '14 at 19:19
  • 1
    For some reason, OPTIONS LRECL only allows up to 32767, despite higher LRECLs certainly being legal on the `FILE` statement. – Joe Apr 09 '14 at 19:20
  • Okay... ran the code, but it is only writing the first 8000 characters of each variable. Why is that? Is there another option I need to change? – Mark Nielsen Apr 09 '14 at 20:11
  • What are the formats/lengths? I would expect to find that $8000. format was on the variables - or perhaps something upstream is truncating them. Are you sure they display all 32767 characters in SAS? – Joe Apr 09 '14 at 20:29
  • This works... I found the issue of truncation is not a SAS issue. I'm pulling a table from a SQL server through ODBC, and that is where the data is getting truncated. – Mark Nielsen Apr 09 '14 at 20:35