<?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: Column header getting suppressed when no data in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Column-header-getting-suppressed-when-no-data/m-p/5846#M2365</link>
    <description>Hi:&lt;BR /&gt;
  But you could use a SAS Macro program to get "around" the issue. There's even a DATA Step method that uses only a few macro variables to get around the issue.&lt;BR /&gt;
[pre]&lt;BR /&gt;
** run a bad query and set data set name;&lt;BR /&gt;
&lt;BR /&gt;
%let mydsn = work.myquery;&lt;BR /&gt;
   &lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table &amp;amp;mydsn as&lt;BR /&gt;
  select * from sashelp.class&lt;BR /&gt;
  where sex = 'm' ;&lt;BR /&gt;
  run;&lt;BR /&gt;
quit;&lt;BR /&gt;
   &lt;BR /&gt;
** now open the data set, get the number of obs,  ;&lt;BR /&gt;
** and close the query data set.;&lt;BR /&gt;
%let dsid=%sysfunc(open(&amp;amp;mydsn));&lt;BR /&gt;
%let nobs=%sysfunc(attrn(&amp;amp;dsid,nobs));&lt;BR /&gt;
%let sysrc=%sysfunc(close(&amp;amp;dsid));&lt;BR /&gt;
   &lt;BR /&gt;
%put -----&amp;gt; dsid= &amp;amp;dsid nobs=&amp;amp;nobs close sysrc=&amp;amp;sysrc;&lt;BR /&gt;
%put -----&amp;gt; Your query ran and created &amp;amp;nobs observations;&lt;BR /&gt;
   &lt;BR /&gt;
ods csv file="c:\temp\want_hdr_anyway.csv";&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  if &amp;amp;nobs = 0 then do;&lt;BR /&gt;
     file print ods;&lt;BR /&gt;
     put _ods_;&lt;BR /&gt;
  end;&lt;BR /&gt;
  set &amp;amp;mydsn;&lt;BR /&gt;
run;&lt;BR /&gt;
    &lt;BR /&gt;
proc print data=&amp;amp;mydsn noobs;&lt;BR /&gt;
run;&lt;BR /&gt;
ods csv close;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
If you run this and the query is bad, the DATA _NULL_ step writes out the headers and one row of missing data because the PDV is built and so the PUT _ODS_ executes BEFORE the set statement tries to read the 0 obs file. Then the PROC PRINT just fails because there are 0 obs -- but the outcome is that you have a CSV file with just the headers. &lt;BR /&gt;
&lt;BR /&gt;
There's a lot that could be done further to "macroize" the program. But without doing much more than this, someone could get headers even if the query failed.&lt;BR /&gt;
&lt;BR /&gt;
IF you try the reverse (create a good query) like this (only change these 2 statements):&lt;BR /&gt;
[pre]&lt;BR /&gt;
** change the LET for the dsn;&lt;BR /&gt;
%let mydsn = work.OKquery;&lt;BR /&gt;
      &lt;BR /&gt;
** change the WHERE statement to generate a good query;&lt;BR /&gt;
 where sex = 'M' ;&lt;BR /&gt;
&lt;BR /&gt;
*** may also want to change the FILE= name if you want to compare the 2 files;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
And then the DATA _NULL_ will execute, but the IF statement will fail, because &amp;amp;NOBS will be greater than 0. So, no harm, no foul from the DATA step -- nothing gets written to ODS. The PROC PRINT will execute and the CSV file will have headers and data.&lt;BR /&gt;
  &lt;BR /&gt;
cynthia</description>
    <pubDate>Wed, 12 Dec 2007 17:59:35 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2007-12-12T17:59:35Z</dc:date>
    <item>
      <title>Column header getting suppressed when no data</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Column-header-getting-suppressed-when-no-data/m-p/5843#M2362</link>
      <description>I am creating CSV file through the below piece of code&lt;BR /&gt;
ods csv file="c:\test\test.csv";&lt;BR /&gt;
proc print data=WORK.QUERY7095;&lt;BR /&gt;
run;&lt;BR /&gt;
ods csv close;&lt;BR /&gt;
When there is no data the csv file is created but without column header.&lt;BR /&gt;
How should i include column header.&lt;BR /&gt;
Any option or any other way to carete csv which will give me column header when no data is there in my report.</description>
      <pubDate>Tue, 11 Dec 2007 11:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Column-header-getting-suppressed-when-no-data/m-p/5843#M2362</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-12-11T11:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Column header getting suppressed when no data</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Column-header-getting-suppressed-when-no-data/m-p/5844#M2363</link>
      <description>ODS is designed not to render "orphaned" headers if no data is present.  You will not be able to do what you want with ODS.&lt;BR /&gt;
&lt;BR /&gt;
-- David Kelley, SAS</description>
      <pubDate>Tue, 11 Dec 2007 14:30:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Column-header-getting-suppressed-when-no-data/m-p/5844#M2363</guid>
      <dc:creator>David_SAS</dc:creator>
      <dc:date>2007-12-11T14:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: Column header getting suppressed when no data</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Column-header-getting-suppressed-when-no-data/m-p/5845#M2364</link>
      <description>it seems such a frequent request, that I'm surprised it doesn't appear on the SASware Ballot 2008 (see &lt;A href="http://support.sas.com/sasware)" target="_blank"&gt;http://support.sas.com/sasware)&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Perhaps there is more interest now than during the 2005 when the idea ranked 16th overall ("add an option to print a special report when no observations are found in the data set" ). &lt;BR /&gt;
&lt;BR /&gt;
PeterC</description>
      <pubDate>Wed, 12 Dec 2007 09:02:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Column-header-getting-suppressed-when-no-data/m-p/5845#M2364</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-12-12T09:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: Column header getting suppressed when no data</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Column-header-getting-suppressed-when-no-data/m-p/5846#M2365</link>
      <description>Hi:&lt;BR /&gt;
  But you could use a SAS Macro program to get "around" the issue. There's even a DATA Step method that uses only a few macro variables to get around the issue.&lt;BR /&gt;
[pre]&lt;BR /&gt;
** run a bad query and set data set name;&lt;BR /&gt;
&lt;BR /&gt;
%let mydsn = work.myquery;&lt;BR /&gt;
   &lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table &amp;amp;mydsn as&lt;BR /&gt;
  select * from sashelp.class&lt;BR /&gt;
  where sex = 'm' ;&lt;BR /&gt;
  run;&lt;BR /&gt;
quit;&lt;BR /&gt;
   &lt;BR /&gt;
** now open the data set, get the number of obs,  ;&lt;BR /&gt;
** and close the query data set.;&lt;BR /&gt;
%let dsid=%sysfunc(open(&amp;amp;mydsn));&lt;BR /&gt;
%let nobs=%sysfunc(attrn(&amp;amp;dsid,nobs));&lt;BR /&gt;
%let sysrc=%sysfunc(close(&amp;amp;dsid));&lt;BR /&gt;
   &lt;BR /&gt;
%put -----&amp;gt; dsid= &amp;amp;dsid nobs=&amp;amp;nobs close sysrc=&amp;amp;sysrc;&lt;BR /&gt;
%put -----&amp;gt; Your query ran and created &amp;amp;nobs observations;&lt;BR /&gt;
   &lt;BR /&gt;
ods csv file="c:\temp\want_hdr_anyway.csv";&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  if &amp;amp;nobs = 0 then do;&lt;BR /&gt;
     file print ods;&lt;BR /&gt;
     put _ods_;&lt;BR /&gt;
  end;&lt;BR /&gt;
  set &amp;amp;mydsn;&lt;BR /&gt;
run;&lt;BR /&gt;
    &lt;BR /&gt;
proc print data=&amp;amp;mydsn noobs;&lt;BR /&gt;
run;&lt;BR /&gt;
ods csv close;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
If you run this and the query is bad, the DATA _NULL_ step writes out the headers and one row of missing data because the PDV is built and so the PUT _ODS_ executes BEFORE the set statement tries to read the 0 obs file. Then the PROC PRINT just fails because there are 0 obs -- but the outcome is that you have a CSV file with just the headers. &lt;BR /&gt;
&lt;BR /&gt;
There's a lot that could be done further to "macroize" the program. But without doing much more than this, someone could get headers even if the query failed.&lt;BR /&gt;
&lt;BR /&gt;
IF you try the reverse (create a good query) like this (only change these 2 statements):&lt;BR /&gt;
[pre]&lt;BR /&gt;
** change the LET for the dsn;&lt;BR /&gt;
%let mydsn = work.OKquery;&lt;BR /&gt;
      &lt;BR /&gt;
** change the WHERE statement to generate a good query;&lt;BR /&gt;
 where sex = 'M' ;&lt;BR /&gt;
&lt;BR /&gt;
*** may also want to change the FILE= name if you want to compare the 2 files;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
And then the DATA _NULL_ will execute, but the IF statement will fail, because &amp;amp;NOBS will be greater than 0. So, no harm, no foul from the DATA step -- nothing gets written to ODS. The PROC PRINT will execute and the CSV file will have headers and data.&lt;BR /&gt;
  &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 12 Dec 2007 17:59:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Column-header-getting-suppressed-when-no-data/m-p/5846#M2365</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-12-12T17:59:35Z</dc:date>
    </item>
  </channel>
</rss>

