<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Dealing with Empty dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708093#M217531</link>
    <description>&lt;P&gt;Yeah I understood that example below are my input datasets and log file : I am not getting message in my log file for "Y" 'NOTE: no output records'&lt;/P&gt;
&lt;P&gt;/***input Datasets**/&lt;/P&gt;
&lt;P&gt;Data X;&lt;BR /&gt;input Num1;&lt;BR /&gt;cards;&lt;BR /&gt;101 &lt;BR /&gt;110 &lt;BR /&gt;102 &lt;BR /&gt;119 &lt;BR /&gt;150 &lt;BR /&gt;109 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;Data Y;&lt;BR /&gt;input Num1;&lt;BR /&gt;cards;&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;;&lt;BR /&gt;run&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/****************************LOG FILE **********************/&lt;/P&gt;
&lt;PRE&gt; 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 NOTE: ODS statements in the SAS Studio environment may disable some output features.
 73         
 74         Data X;
 75         input Num1;
 76         cards;
 
 NOTE: The data set WORK.X has 6 observations and 1 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              778.25k
       OS Memory           41432.00k
       Timestamp           12/24/2020 03:40:24 PM
       Step Count                        251  Switch Count  2
       Page Faults                       0
       Page Reclaims                     91
       Page Swaps                        0
       Voluntary Context Switches        9
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           264
       
 
 83         ;
 84         run;
 85         Data Y;
 86         input Num1;
 87         cards;
 
 NOTE: The data set WORK.Y has 6 observations and 1 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              778.25k
       OS Memory           41432.00k
       Timestamp           12/24/2020 03:40:24 PM
       Step Count                        252  Switch Count  2
       Page Faults                       0
       Page Reclaims                     88
       Page Swaps                        0
       Voluntary Context Switches        11
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           264
       
 
 94         ;
 95         run
 96         
 97         
 98         ods excel file='my_report.xlsx';
 99         
 100        proc print data=Y ;
 101        run;
 
 NOTE: There were 6 observations read from the data set WORK.Y.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           0.03 seconds
       user cpu time       0.03 seconds
       system cpu time     0.00 seconds
       memory              1932.00k
       OS Memory           41688.00k
       Timestamp           12/24/2020 03:40:24 PM
       Step Count                        253  Switch Count  0
       Page Faults                       0
       Page Reclaims                     79
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           24
       
 
 102        
 103        
 104        data _null_;
 105          file print;
 106          if nobs=0 then put 'NOTE: no output records';
 107          stop;
 108          set Y nobs=nobs;
 109        run;
 
 NOTE: 0 lines were written to file PRINT.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              779.50k
       OS Memory           41944.00k
       Timestamp           12/24/2020 03:40:24 PM
       Step Count                        254  Switch Count  0
       Page Faults                       0
       Page Reclaims                     83
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           0
       
 
 110        
 111        
 112        proc print data=X;
 113        run;
 
 NOTE: There were 6 observations read from the data set WORK.X.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           0.02 seconds
       user cpu time       0.02 seconds
       system cpu time     0.00 seconds
       memory              588.59k
       OS Memory           41944.00k
       Timestamp           12/24/2020 03:40:25 PM
       Step Count                        255  Switch Count  0
       Page Faults                       0
       Page Reclaims                     72
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           16
       
 
 114        
 115        
 116        data _null_;
 117          file print;
 118          if nobs=0 then put 'NOTE: no output records';
 119          stop;
 120          set X nobs=nobs;
 121        run;
 
 NOTE: 0 lines were written to file PRINT.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              779.50k
       OS Memory           41944.00k
       Timestamp           12/24/2020 03:40:25 PM
       Step Count                        256  Switch Count  0
       Page Faults                       0
       Page Reclaims                     71
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           0
       
 
 122        
 123        OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 135        &lt;/PRE&gt;</description>
    <pubDate>Thu, 24 Dec 2020 15:43:07 GMT</pubDate>
    <dc:creator>librasonali</dc:creator>
    <dc:date>2020-12-24T15:43:07Z</dc:date>
    <item>
      <title>Dealing with Empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708074#M217521</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not able to find an approach for the below case. I hope I will get help&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 1 dataset 'X' which has a few records whereas 2nd dataset "Y" has 0 records. &lt;BR /&gt;I want that the X dataset should export its record into an xslx sheet whereas for Dataset Y it should put "NOTE: no output records";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance !&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Dec 2020 13:24:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708074#M217521</guid>
      <dc:creator>librasonali</dc:creator>
      <dc:date>2020-12-24T13:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: Dealing with Empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708087#M217526</link>
      <description>&lt;P&gt;This is a common reporting request and easy to solve.&amp;nbsp; Just use two steps only one of which will&amp;nbsp; produce output.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods excel file='my_report.xlsx';

proc print data=have ;
run;
data _null_;
  file print;
  if nobs=0 then put 'NOTE: no output records';
&amp;nbsp;&amp;nbsp;stop;
&amp;nbsp;&amp;nbsp;set&amp;nbsp;have&amp;nbsp;nobs=nobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Dec 2020 14:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708087#M217526</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-24T14:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Dealing with Empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708090#M217528</link>
      <description>what is have here ??&lt;BR /&gt;how can I use X and Y ??? &lt;BR /&gt;</description>
      <pubDate>Thu, 24 Dec 2020 15:23:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708090#M217528</guid>
      <dc:creator>librasonali</dc:creator>
      <dc:date>2020-12-24T15:23:05Z</dc:date>
    </item>
    <item>
      <title>Re: Dealing with Empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708091#M217529</link>
      <description>&lt;P&gt;HAVE is the name of the dataset you want to report.&amp;nbsp; So if your actual dataset is named X then replace HAVE with X.&amp;nbsp; If you have more than one dataset then repeat the for that dataset.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Dec 2020 15:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708091#M217529</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-24T15:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Dealing with Empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708093#M217531</link>
      <description>&lt;P&gt;Yeah I understood that example below are my input datasets and log file : I am not getting message in my log file for "Y" 'NOTE: no output records'&lt;/P&gt;
&lt;P&gt;/***input Datasets**/&lt;/P&gt;
&lt;P&gt;Data X;&lt;BR /&gt;input Num1;&lt;BR /&gt;cards;&lt;BR /&gt;101 &lt;BR /&gt;110 &lt;BR /&gt;102 &lt;BR /&gt;119 &lt;BR /&gt;150 &lt;BR /&gt;109 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;Data Y;&lt;BR /&gt;input Num1;&lt;BR /&gt;cards;&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;;&lt;BR /&gt;run&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/****************************LOG FILE **********************/&lt;/P&gt;
&lt;PRE&gt; 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 NOTE: ODS statements in the SAS Studio environment may disable some output features.
 73         
 74         Data X;
 75         input Num1;
 76         cards;
 
 NOTE: The data set WORK.X has 6 observations and 1 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              778.25k
       OS Memory           41432.00k
       Timestamp           12/24/2020 03:40:24 PM
       Step Count                        251  Switch Count  2
       Page Faults                       0
       Page Reclaims                     91
       Page Swaps                        0
       Voluntary Context Switches        9
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           264
       
 
 83         ;
 84         run;
 85         Data Y;
 86         input Num1;
 87         cards;
 
 NOTE: The data set WORK.Y has 6 observations and 1 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              778.25k
       OS Memory           41432.00k
       Timestamp           12/24/2020 03:40:24 PM
       Step Count                        252  Switch Count  2
       Page Faults                       0
       Page Reclaims                     88
       Page Swaps                        0
       Voluntary Context Switches        11
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           264
       
 
 94         ;
 95         run
 96         
 97         
 98         ods excel file='my_report.xlsx';
 99         
 100        proc print data=Y ;
 101        run;
 
 NOTE: There were 6 observations read from the data set WORK.Y.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           0.03 seconds
       user cpu time       0.03 seconds
       system cpu time     0.00 seconds
       memory              1932.00k
       OS Memory           41688.00k
       Timestamp           12/24/2020 03:40:24 PM
       Step Count                        253  Switch Count  0
       Page Faults                       0
       Page Reclaims                     79
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           24
       
 
 102        
 103        
 104        data _null_;
 105          file print;
 106          if nobs=0 then put 'NOTE: no output records';
 107          stop;
 108          set Y nobs=nobs;
 109        run;
 
 NOTE: 0 lines were written to file PRINT.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              779.50k
       OS Memory           41944.00k
       Timestamp           12/24/2020 03:40:24 PM
       Step Count                        254  Switch Count  0
       Page Faults                       0
       Page Reclaims                     83
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           0
       
 
 110        
 111        
 112        proc print data=X;
 113        run;
 
 NOTE: There were 6 observations read from the data set WORK.X.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           0.02 seconds
       user cpu time       0.02 seconds
       system cpu time     0.00 seconds
       memory              588.59k
       OS Memory           41944.00k
       Timestamp           12/24/2020 03:40:25 PM
       Step Count                        255  Switch Count  0
       Page Faults                       0
       Page Reclaims                     72
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           16
       
 
 114        
 115        
 116        data _null_;
 117          file print;
 118          if nobs=0 then put 'NOTE: no output records';
 119          stop;
 120          set X nobs=nobs;
 121        run;
 
 NOTE: 0 lines were written to file PRINT.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              779.50k
       OS Memory           41944.00k
       Timestamp           12/24/2020 03:40:25 PM
       Step Count                        256  Switch Count  0
       Page Faults                       0
       Page Reclaims                     71
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           0
       
 
 122        
 123        OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 135        &lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Dec 2020 15:43:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708093#M217531</guid>
      <dc:creator>librasonali</dc:creator>
      <dc:date>2020-12-24T15:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: Dealing with Empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708161#M217563</link>
      <description>&lt;P&gt;Do you mean this note?&lt;/P&gt;
&lt;PRE&gt;NOTE: 0 lines were written to file PRINT.&lt;/PRE&gt;
&lt;P&gt;That is what you want.&amp;nbsp; Since the dataset was NOT empty your don't want to write anything into the PRINT (which you have directed to EXCEL with the ODS EXCEL statement).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make sure to close the ODS EXECL destination when you are done making your report.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Dec 2020 03:47:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708161#M217563</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-25T03:47:33Z</dc:date>
    </item>
    <item>
      <title>Re: Dealing with Empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708401#M217703</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Do you mean this note?&lt;/P&gt;
&lt;PRE&gt;NOTE: 0 lines were written to file PRINT.&lt;/PRE&gt;
&lt;P&gt;That is what you want.&amp;nbsp; Since the dataset was NOT empty your don't want to write anything into the PRINT (which you have directed to EXCEL with the ODS EXCEL statement).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make sure to close the ODS EXECL destination when you are done making your report.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;HR /&gt;
&lt;P&gt;&lt;BR /&gt;I want that the dataset which have records with populated values should be exported into a CSV where as the Dataset which is empty should so me the message in my log file&amp;nbsp;'NOTE: no output records'.&lt;/P&gt;
&lt;P class="1609152405313"&gt;Current Situation : In both of my cases a csv is generated which&amp;nbsp; blank i.e no observations.&amp;nbsp;&lt;SPAN&gt;0 lines were written to file PRINT.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="1609152405313"&gt;Expected : The missing data should not at all generate a CSV as it is expected to give a log message.&amp;nbsp;&lt;/P&gt;
&lt;P class="1609152405313"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="1609152405313"&gt;Please find below my code :&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input cusip_id Name $10. date_issue :ddmmyy10. type $10.;
format date_issue ddmmyy10.;
datalines;
10343452 Zingas    01/04/2016 bench
10343489 Stephanie 01/04/2014 main
10343445 Olivia    01/04/2012 main
10343456 Amstel    01/04/2011 bench
10343457 KEO       01/04/2017 main
10343456 Sonali    01/04/2011 ITP
;
proc print;
run;

data want;
input cusip_id ;
datalines;
.
.
.
.
.
.
.
;

run;
/*First dataset*/
ods csv file="/home/u49388206/cert/excel/NOTEMPTY.csv";

data _NULL_;
set have ;
file print;
if nobs=0  then put 'NOTE: no output records';
stop;
set have nobs=nobs;
run;

ods csvall close; 

/*second dataset*/

ods csv file="/home/u49388206/cert/excel/EMPTY.csv";

data _NULL_;
set want ;
file print;
if nobs=0 then put 'NOTE: no output records';
stop;
set want nobs=nobs;
run;

ods csvall close; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="1609152405313"&gt;Thanks For the help you are doing !&amp;nbsp;&lt;/P&gt;
&lt;P class="1609152405313"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="1609152405313"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Dec 2020 15:06:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708401#M217703</guid>
      <dc:creator>librasonali</dc:creator>
      <dc:date>2020-12-28T15:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: Dealing with Empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708437#M217716</link>
      <description>&lt;P&gt;So you don't want to make an EXCEL file at all? Just delimited text files?&amp;nbsp; What do you want to make for an empty dataset?&amp;nbsp; Do you want to not create any file at all?&amp;nbsp; Do you want to create a file with just the column headers?&amp;nbsp; Do you want to delete any existing file with that target filename?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are using a recent enough version of SAS you can use a %IF/%THEN/%DO construct in open code.&amp;nbsp; With older versions you might need to use a macro or some other method to prevent the "export" step from running.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can set a macro variable with the number of observations in the dataset and then decide what to do.&amp;nbsp; For example like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symputx('nobs',nobs);
  stop;
  set want nobs=nobs;
run;
%if &amp;amp;nobs &amp;gt; 0 %then %do;
  *** Code to write the CSV file ***
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that CSV files are easy to write without using ODS or PROC EXPORT.&amp;nbsp; Here is a method that just uses two data steps. One to write the header line and one to write the data.&amp;nbsp; So this will create a file with just the header row when the input dataset has zero observations.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=HAVE(obs=0) out=names; 
  var _all_;
run;
data _null_;
  file 'have.csv' dsd ;
  set names;
  put _name_ @@;
run;
data _null_;
  file 'have.csv' dsd mod ;
  set have;
  put (_all_) (+0);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Dec 2020 15:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708437#M217716</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-28T15:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: Dealing with Empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708537#M217768</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;So you don't want to make an EXCEL file at all? Just delimited text files?&amp;nbsp; What do you want to make for an empty dataset?&amp;nbsp; Do you want to not create any file at all?&amp;nbsp; Do you want to create a file with just the column headers?&amp;nbsp; Do you want to delete any existing file with that target filename?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are using a recent enough version of SAS you can use a %IF/%THEN/%DO construct in open code.&amp;nbsp; With older versions you might need to use a macro or some other method to prevent the "export" step from running.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can set a macro variable with the number of observations in the dataset and then decide what to do.&amp;nbsp; For example like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symputx('nobs',nobs);
  stop;
  set want nobs=nobs;
run;
%if &amp;amp;nobs &amp;gt; 0 %then %do;
  *** Code to write the CSV file ***
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that CSV files are easy to write without using ODS or PROC EXPORT.&amp;nbsp; Here is a method that just uses two data steps. One to write the header line and one to write the data.&amp;nbsp; So this will create a file with just the header row when the input dataset has zero observations.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=HAVE(obs=0) out=names; 
  var _all_;
run;
data _null_;
  file 'have.csv' dsd ;
  set names;
  put _name_ @@;
run;
data _null_;
  file 'have.csv' dsd mod ;
  set have;
  put (_all_) (+0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt; What do you want to make for an empty dataset? ---&lt;FONT color="#0000FF"&gt; I want to put message in log " NOTE: empty dataset" instead of&amp;nbsp; generating a CSV file or an excel file.&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;Currently, in both the cases a csv is generated.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2020 09:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dealing-with-Empty-dataset/m-p/708537#M217768</guid>
      <dc:creator>librasonali</dc:creator>
      <dc:date>2020-12-29T09:31:44Z</dc:date>
    </item>
  </channel>
</rss>

