<?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: Only headers in csv when there's no data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Only-headers-in-csv-when-there-s-no-data/m-p/429486#M281491</link>
    <description>&lt;P&gt;The order of the statements in your data step is wrong. SAS will stop when&amp;nbsp;the SET statement&amp;nbsp;reads past the end of the data.&lt;/P&gt;
&lt;P&gt;The order should look like this.&amp;nbsp; Then it will write the headers even if the input has 0 observations.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file ... ;
  if _n_=1 then ... ;
  set ... ;
  put ... ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 21 Jan 2018 19:37:40 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-01-21T19:37:40Z</dc:date>
    <item>
      <title>Only headers in csv when there's no data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-headers-in-csv-when-there-s-no-data/m-p/429464#M281488</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to export a csv file with only the headers when there's no data to export?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For multiple purpose I automatically generate csv files that will be retrieved by other parties. They can only process the csv files when the column headers are always shown.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But now, when for some reason there's no data to export, also the column headers are left out. This causes fail overs at the receiving end.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the example of the way I now publish the csv file;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Headers.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18009i13EF2AA6D5341FF8/image-size/large?v=v2&amp;amp;px=999" role="button" title="Headers.PNG" alt="Headers.PNG" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2018 13:11:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-headers-in-csv-when-there-s-no-data/m-p/429464#M281488</guid>
      <dc:creator>PWS</dc:creator>
      <dc:date>2018-01-21T13:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: Only headers in csv when there's no data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-headers-in-csv-when-there-s-no-data/m-p/429481#M281489</link>
      <description>&lt;P&gt;The %DS2CSV Macro handles this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* With observations */
%ds2csv(data=sashelp.class, runmode=b, csvfile=YourPathHere\class.csv);

/* Without Observations */
data NoObsClass;
   set sashelp.class(obs=0);
run;

%ds2csv(data=NoObsClass, runmode=b, csvfile=YourPathHere\NoObsClass.csv);

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2018 17:38:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-headers-in-csv-when-there-s-no-data/m-p/429481#M281489</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-01-21T17:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: Only headers in csv when there's no data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-headers-in-csv-when-there-s-no-data/m-p/429482#M281490</link>
      <description>&lt;P&gt;You can read about the macro in the &lt;A href="http://go.documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lebaseutilref&amp;amp;docsetTarget=n0yo3bszlrh0byn1j4fxh4ndei8u.htm&amp;amp;locale=en#p0y7l30qygje7yn1a25091r9e0a4" target="_self"&gt;DS2CSV Documentation&amp;nbsp;&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2018 17:39:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-headers-in-csv-when-there-s-no-data/m-p/429482#M281490</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-01-21T17:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: Only headers in csv when there's no data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-headers-in-csv-when-there-s-no-data/m-p/429486#M281491</link>
      <description>&lt;P&gt;The order of the statements in your data step is wrong. SAS will stop when&amp;nbsp;the SET statement&amp;nbsp;reads past the end of the data.&lt;/P&gt;
&lt;P&gt;The order should look like this.&amp;nbsp; Then it will write the headers even if the input has 0 observations.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file ... ;
  if _n_=1 then ... ;
  set ... ;
  put ... ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 21 Jan 2018 19:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-headers-in-csv-when-there-s-no-data/m-p/429486#M281491</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-01-21T19:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Only headers in csv when there's no data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-headers-in-csv-when-there-s-no-data/m-p/429555#M281492</link>
      <description>Thanks! This works!</description>
      <pubDate>Mon, 22 Jan 2018 08:06:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-headers-in-csv-when-there-s-no-data/m-p/429555#M281492</guid>
      <dc:creator>PWS</dc:creator>
      <dc:date>2018-01-22T08:06:23Z</dc:date>
    </item>
  </channel>
</rss>

