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

Hi experts,

 

I'm using "proc export" to generate a file with the option putnames=no, when the file has at least one record i don´t have any problem, but when the file is empty, the files is generated (0 bytes, just the name), but the sas program returns me this message 

 

NOTE: 0 records were written to the file '/sasdatos/xxxxx/crea.txt'.
NOTE: There were 0 observations read from the data set WORK.PRUEBA.
NOTE: Sentencia DATA used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

0 records created in /sasdatos/xxxxx/crea.txt from WORK.PRUEBA.
ERROR: Export unsuccessful. See SAS Log for details.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDIMIENTO EXPORT used (Total process time):
real time 0.05 seconds
cpu time 0.06 seconds

 

The program stops, and it doesn´t continue, can any one help me to work around this ?  Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You didn't show what TYPE of file you asked PROC EXPORT to make, but since the extension is .TXT it is probably something you could make using a simple data step instead.

 

For example to make a tab delimited file without a header row just do this:

data _null_;
   file "myfile.txt" dsd dlm='09'x ;
   set have ;
   put (_all_) (+0);
run;

 

Note that for me PROC EXPORT does NOT generate that ERROR message.  Are you running something else that is generating that error message?  This code runs fine.

filename csv temp;
proc export file=csv data=sashelp.class(obs=0) dbms=csv; run;

What version of SAS are you running?  See this usage note:  http://support.sas.com/kb/62/386.html

View solution in original post

8 REPLIES 8
Tom
Super User Tom
Super User

Huh?

If there are no lines of data and no header line then the file SHOULD be empty.

Jose6
Obsidian | Level 7
The problem it is not the empty file, the problem is the error being
generated by this, I want to avoid the error in order to continue with the
other part of the program
Tom
Super User Tom
Super User

You didn't show what TYPE of file you asked PROC EXPORT to make, but since the extension is .TXT it is probably something you could make using a simple data step instead.

 

For example to make a tab delimited file without a header row just do this:

data _null_;
   file "myfile.txt" dsd dlm='09'x ;
   set have ;
   put (_all_) (+0);
run;

 

Note that for me PROC EXPORT does NOT generate that ERROR message.  Are you running something else that is generating that error message?  This code runs fine.

filename csv temp;
proc export file=csv data=sashelp.class(obs=0) dbms=csv; run;

What version of SAS are you running?  See this usage note:  http://support.sas.com/kb/62/386.html

Kurt_Bremser
Super User

Instead of running proc export, copy the data step from the log and run only that. As you can see in the log, the data step itself returns only NOTEs.

ScottBass
Rhodochrosite | Level 12

Perhaps this would help:

https://github.com/scottbass/SAS/blob/master/Macro/export.sas

 

Stolen from:

https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-use-labels-in-proc-export-or-create-tab...


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
Amir
PROC Star

You could try using something like the following macro that exports a data set to a file and if the data set is empty it just creates an empty file without generating an error.

 

/* define a macro to export a data set to a file or */
/* create an empty file if the data set has 0 obs   */
%macro export_ds(dsname,fpath,fname);
   /* check how many obs are in data set */
   data _null_;
      call symputx('nobs',nobs);
      set &dsname(obs = 0) nobs = nobs;
   run;

   /* if there any obs in data set then export */
   %if &nobs %then
   %do;
      proc export
         data    = &dsname
         outfile = "&fpath/&fname"
         ;
      run;
   %end;
   /* otherwise create empty file */
   %else
   %do;
      data _null_;
         file "&fpath/&fname";
      run;
   %end;
%mend export_ds;

 

Some example calls to the macro, one with data in the data set and another with an empty data set.

NB. Replace "your/file/path" in the below macro calls with your actual file path.

 

/* macro diagnostic messages in log */
options symbolgen mlogic mprint;

/* execute macro with a data set of 19 obs */
%export_ds(sashelp.class,your/file/path,tmp.txt)

/* set up a data set with 0 obs */
data have;
   set sashelp.class(obs = 0);
run;

/* execute macro with a data set of 0 obs */
%export_ds(have,your/file/path,want.txt)

HTH.

 

Amir.

Jose6
Obsidian | Level 7

Thank you all, It was a great help!

ballardw
Super User

@Jose6 wrote:

Hi experts,

 

I'm using "proc export" to generate a file with the option putnames=no, when the file has at least one record i don´t have any problem, but when the file is empty, the files is generated (0 bytes, just the name), but the sas program returns me this message 

 

NOTE: 0 records were written to the file '/sasdatos/xxxxx/crea.txt'.
NOTE: There were 0 observations read from the data set WORK.PRUEBA.
NOTE: Sentencia DATA used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

0 records created in /sasdatos/xxxxx/crea.txt from WORK.PRUEBA.
ERROR: Export unsuccessful. See SAS Log for details.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDIMIENTO EXPORT used (Total process time):
real time 0.05 seconds
cpu time 0.06 seconds

 

The program stops, and it doesn´t continue, can any one help me to work around this ?  Thanks!


What do you want to happen when you request an export with nothing to export???

 

One approach would be to use a data step to write the text file instead of proc export. Data steps would not generate any error. If you exporting similar files you should be able to find code to export a file in that format in the log of a successful run because Export will write the data step code to the log.

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
  • 8 replies
  • 3697 views
  • 1 like
  • 6 in conversation