1
votes

I want to export multiple SAS datasets as CSV files (not as xlsx files) using SAS 9.4. When using the code for any of the datasets:

proc export data = dataset
    outfile = "C:\MBorg\dataset.csv"
    dbms = csv replace;
run;

I receive this error message:

ERROR: Export unsuccessful.  See SAS Log for details.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE EXPORT used (Total process time):
      real time           0.06 seconds
      cpu time            0.01 seconds

Contrary to what the error message suggests, the SAS log provides no extra details.

Folder permissions or having Excel closed or open when running the code as per this question's answer, or using an empty dataset, makes no difference. The SAS website mentions that this error can occur when using PROC EXPORT with DBMS=CSV, and it can be avoided by using name-literal syntax. However, using it as per below makes no difference.

proc export data = work.'dataset'n
    outfile = "C:\MBorg\dataset.csv"
    dbms = csv replace;
run;

Strangely the only way I can find to circumvent the problem is resetting SAS. options obs=max makes no difference. Not sure what causes this message. This occurred with SAS 9.4 M0 and M7.

Any help with exporting CSV files without resetting SAS would be helpful.

1
You might have gotten an earlier error that changed something. For example it might have set the option OBS=0 which would prevent the data step that PROC EXPORT generates from reading/writing any data.Tom
Do you know what errors could set that option?MBorg
@Tom tried options obs=max and it did not remove the code. This error seems to occur after prolonged use of SAS, and closing/reopening SAS is the only way I've found to circumvent it for the last few years.MBorg
Since you are writing text files you don't need to use PROC EXPORT. Just write your own data step(s) to write the CSV files. That might let you get a more meaningful error message.Tom

1 Answers

1
votes

Try writing your own step(s) to write the text file instead of asking PROC EXPORT to generate one for you. That should at least make the error message clearer.

* Get list of variables names ;
proc transpose data=DATASET(obs=0) out=_names_; var _all_; run;
* Write header row ;
data _null_;
  file "C:\MBorg\dataset.csv" dsd lrecl=2000000 ;
  set _names_;
  put _name_ @ ;
run;
* Write data rows ;
data _null_;
  file "C:\MBorg\dataset.csv" dsd lrecl=2000000 mod;
  set DATASET;
  put (_all_) (+0) ;
run;