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!
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
Huh?
If there are no lines of data and no header line then the file SHOULD be empty.
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
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.
Perhaps this would help:
https://github.com/scottbass/SAS/blob/master/Macro/export.sas
Stolen from:
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.
Thank you all, It was a great help!
@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 seconds0 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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.