<?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: export data set to excel only when data set contains data in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/export-data-set-to-excel-only-when-data-set-contains-data/m-p/238694#M17185</link>
    <description>&lt;P&gt;Well,&amp;nbsp;several ways of doing this. &amp;nbsp;Tomy mind the simplest is:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set have (obs=1 where=(col1=""));
  call execute('proc export data=have outfile="c:\temp.xls"; run;');
run;&lt;/PRE&gt;
&lt;P&gt;So what this does is take one observation (obs=1) from HAVE dataset where a missing is found. &amp;nbsp;If a record exists for that logic then the text in the call execute is sent to the compiler after the datastep is finished. &amp;nbsp;If no records are returned, i.e. all are present, then that call execute code is never carried out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Dec 2015 14:51:39 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2015-12-10T14:51:39Z</dc:date>
    <item>
      <title>export data set to excel only when data set contains data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/export-data-set-to-excel-only-when-data-set-contains-data/m-p/238686#M17184</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;How can I export my data set to excel if and only if my data set contains values? I run my code on a daily basis, and if a condition is met, then I want to export my table to excel. If the condition is not met, I don't want to export my table. i.e.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ran my code yesterday, and&amp;nbsp;col1 have 'a' in all rows. I don't want to export my table to excel today.&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="164" style="width: 124pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL width="82" style="width: 62pt;" span="2" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 13.2pt;"&gt;
&lt;TD width="82" height="18" style="border: 0px black; width: 62pt; height: 13.2pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;id&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="82" style="border: 0px black; width: 62pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;col1&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 13.2pt;"&gt;
&lt;TD height="18" align="right" style="border: 0px black; height: 13.2pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;a&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 13.2pt;"&gt;
&lt;TD height="18" align="right" style="border: 0px black; height: 13.2pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;a&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 13.2pt;"&gt;
&lt;TD height="18" align="right" style="border: 0px black; height: 13.2pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;a&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 13.2pt;"&gt;
&lt;TD height="18" align="right" style="border: 0px black; height: 13.2pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;4&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;a&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I run my code today, and col1 is missing 'a' in 2 rows. I wan't to export my table to excel today.&lt;/P&gt;
&lt;TABLE width="164" style="width: 124pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL width="82" style="width: 62pt;" span="2" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 13.2pt;"&gt;
&lt;TD width="82" height="18" style="border: 0px black; width: 62pt; height: 13.2pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;id&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="82" style="border: 0px black; width: 62pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;col1&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 13.2pt;"&gt;
&lt;TD height="18" align="right" style="border: 0px black; height: 13.2pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; background-color: transparent;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 13.2pt;"&gt;
&lt;TD height="18" align="right" style="border: 0px black; height: 13.2pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;a&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 13.2pt;"&gt;
&lt;TD height="18" align="right" style="border: 0px black; height: 13.2pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; background-color: transparent;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 13.2pt;"&gt;
&lt;TD height="18" align="right" style="border: 0px black; height: 13.2pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;4&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;a&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I wirte a code that only exports my table to excel if col1 has missing values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2015 13:51:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/export-data-set-to-excel-only-when-data-set-contains-data/m-p/238686#M17184</guid>
      <dc:creator>ak2</dc:creator>
      <dc:date>2015-12-10T13:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: export data set to excel only when data set contains data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/export-data-set-to-excel-only-when-data-set-contains-data/m-p/238694#M17185</link>
      <description>&lt;P&gt;Well,&amp;nbsp;several ways of doing this. &amp;nbsp;Tomy mind the simplest is:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set have (obs=1 where=(col1=""));
  call execute('proc export data=have outfile="c:\temp.xls"; run;');
run;&lt;/PRE&gt;
&lt;P&gt;So what this does is take one observation (obs=1) from HAVE dataset where a missing is found. &amp;nbsp;If a record exists for that logic then the text in the call execute is sent to the compiler after the datastep is finished. &amp;nbsp;If no records are returned, i.e. all are present, then that call execute code is never carried out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2015 14:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/export-data-set-to-excel-only-when-data-set-contains-data/m-p/238694#M17185</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-12-10T14:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: export data set to excel only when data set contains data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/export-data-set-to-excel-only-when-data-set-contains-data/m-p/238696#M17186</link>
      <description>&lt;P&gt;Here is what I came up with, but I like &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9﻿&lt;/a&gt;'s solution *much* better for brevity and efficiency, assuming you don't need the actual count of missing values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/* count the number of missing values and store result in a macro variable */
proc sql noprint;
	select count(case when MISSING(col1) then "count me" end)
	into :missingCount
	from mydata;
quit;

/* if one or more missing values found, export */
%macro exportIfMissing;
%if &amp;amp;missingCount &amp;gt; 0 %then %do;
	%put NOTE: Missing values found, so exporting to Excel...;
	proc export data=mydata outfile="c:\temp\mydata.xlsx";
	run;
%end;
%else %do;
	%put NOTE: No missing values found.  So, not exporting;
%end;
%mend;
%exportIfMissing;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2015 15:00:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/export-data-set-to-excel-only-when-data-set-contains-data/m-p/238696#M17186</guid>
      <dc:creator>CaseySmith</dc:creator>
      <dc:date>2015-12-10T15:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: export data set to excel only when data set contains data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/export-data-set-to-excel-only-when-data-set-contains-data/m-p/238709#M17188</link>
      <description>&lt;P&gt;As an aside...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can create conditions in EG process flows to control the order of execution with if/then/else logic.&amp;nbsp; These EG process flow conditions can be based on macro variable values.&amp;nbsp; So, storing the "missing value present"&amp;nbsp;result in a macro variable would allow you to use it in a condition in an EG process flow.&amp;nbsp; For example, if you wanted to use the point-and-click&amp;nbsp;&lt;STRONG&gt;Export as a Step in Project&lt;/STRONG&gt; task to export the data&amp;nbsp;rather than code (some do, some don't),&amp;nbsp;you could use the macro variable value (which would reflect whether missing values were present)&amp;nbsp;to decide whether to run the task during a process flow or project run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: EG process flow conditions are only applicable when executed in the context of EG.&amp;nbsp; So, if you plan to execute outside of EG, you should stick with code to do the conditional logic.&amp;nbsp; For programmers, the code is often easier anyway.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2015 15:40:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/export-data-set-to-excel-only-when-data-set-contains-data/m-p/238709#M17188</guid>
      <dc:creator>CaseySmith</dc:creator>
      <dc:date>2015-12-10T15:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: export data set to excel only when data set contains data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/export-data-set-to-excel-only-when-data-set-contains-data/m-p/238877#M17190</link>
      <description>&lt;P&gt;Both methods worked just fine. Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2015 10:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/export-data-set-to-excel-only-when-data-set-contains-data/m-p/238877#M17190</guid>
      <dc:creator>ak2</dc:creator>
      <dc:date>2015-12-11T10:39:07Z</dc:date>
    </item>
  </channel>
</rss>

