Search code examples
sasexportexport-to-csvproc

SAS PROC EXPORT and DBMS=CSV. ERROR: Export unsuccessful. See SAS Log for details


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.


Solution

  • 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;