<?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: SAS DI : Job to  check for empty datasets and e-mail all empty datasets in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555545#M17014</link>
    <description>&lt;P&gt;Hi Erik,&lt;/P&gt;&lt;P&gt;Yes,Thanks for your help.&lt;/P&gt;</description>
    <pubDate>Thu, 02 May 2019 08:34:01 GMT</pubDate>
    <dc:creator>JJP1</dc:creator>
    <dc:date>2019-05-02T08:34:01Z</dc:date>
    <item>
      <title>SAS DI : Job to  check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/554693#M17001</link>
      <description>&lt;P&gt;We have SAS V9 jobs running as part of daily batch and daily data sets&amp;nbsp; will be updated.&lt;/P&gt;&lt;P&gt;but sometimes we have datasets with out data( having zero observations) getting updated assume even though it should update with records please )so datasets will be creating with no data.&lt;/P&gt;&lt;P&gt;We need to get e-mail automatically with datasets that are having zero observations.&lt;/P&gt;&lt;P&gt;please note that it is not related to specific library or specific data set we have this issue.this issue can occur in any library for any dataset which we need to take care of scenarios&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please suggest the best way to do this.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2019 13:40:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/554693#M17001</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2019-04-29T13:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to  check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/554718#M17002</link>
      <description>&lt;P&gt;While you wait for a DI-specific solution, here's a custom code option that will at least keep you going. It creates an empty dataset, and then the PROC SQL program puts the record count into a macro variable. If your SAS version is new enough to allow %if structures in open code, you can just use the piece underneath (substitute your sending the email for the "proc print", otherwise wrap it in a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The %put statement isn't needed, I just added it for additional confirmation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
	a = 1;
	stop;
run;

proc sql noprint;
	select count(*) into :RecCount from Have;
quit;

%put &amp;amp;=RecCount;

%if &amp;amp;RecCount = 0 %then
	%do;

		proc print data=sashelp.class;
		run;

	%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Apr 2019 14:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/554718#M17002</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2019-04-29T14:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/554999#M17003</link>
      <description>Hi,&lt;BR /&gt;I don't want to create empty sas datset please.&lt;BR /&gt;I just need to get email that what are all the sas datasets with names&lt;BR /&gt;telling there are empty.so That I can verify later on why it has no data.&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Apr 2019 12:53:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/554999#M17003</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2019-04-30T12:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555046#M17004</link>
      <description>&lt;P&gt;Okay, suppose the dataset you want to check is "SASUser.Have".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code will do what you need, just substitute the code to send the email where this line is:&lt;/P&gt;
&lt;P&gt;/* Code to send email about SASUser.Have */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
	select count(*) into :RecCount from SASUser.Have;
quit;

%if &amp;amp;RecCount = 0 %then
	%do;

		/* Code to send email about SASUser.Have */

	%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Apr 2019 14:04:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555046#M17004</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2019-04-30T14:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555082#M17005</link>
      <description>Sorry Tom to confuse you.&lt;BR /&gt;Actually we don't know which datset can be created with 0 observations as&lt;BR /&gt;part of daily sas batch jobd.&lt;BR /&gt;Actually here we know already the name of dataset and library. Would you&lt;BR /&gt;please help me assuming I dont know the dataset name or library where we&lt;BR /&gt;have this case please. How can we handle this case please&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Apr 2019 15:16:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555082#M17005</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2019-04-30T15:16:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555111#M17006</link>
      <description>&lt;P&gt;In that case, it will depend on whether there is a facility in SAS DI to do this check. I'm not aware of one; hopefully somebody more expert than me can help you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck!&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 16:13:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555111#M17006</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2019-04-30T16:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to  check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555185#M17007</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would need some clarification from you regarding the specific problem you are facing prior to helping you find a suitable solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe you have a number of SAS libraries that contain data sets that you wish to monitor for zero observations?&lt;/P&gt;
&lt;P&gt;Is this correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are multiple SAS libraries involved but you do know prior to batch job execution which SAS libraries contain the data sets that need to be monitored for zero observations?&lt;/P&gt;
&lt;P&gt;Is this correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You wish to trigger a single email message that lists those input/output tables that contain zero observations?&lt;/P&gt;
&lt;P&gt;Is this correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you wishing to track input tables (tables that will update a target table) for zero observations or are you wishing to track the final updated target tables for zero observations?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having a better understanding of the desired process flow will help me to locate a suitable solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks very much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 19:30:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555185#M17007</guid>
      <dc:creator>ChrisLysholm</dc:creator>
      <dc:date>2019-04-30T19:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to  check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555438#M17009</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/256123"&gt;@JJP1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A simple solution is to create a User Transformation in DI Studio with code to check the number of records and take appropriate action.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DI Studio creates a score of macro variables at the top of each transformation describing input and output, among these is the macro variable &amp;amp;_INPUT with the actual library.dataset name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the user transformation is&amp;nbsp;added to a DI Studio job as the last transfromation with the table as input, you can use &amp;amp;_INPUT to refer to the data set in the transformation code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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-left" image-alt="stop.gif" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29151i76E506012FEE1346/image-size/large?v=v2&amp;amp;px=999" role="button" title="stop.gif" alt="stop.gif" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2019 18:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555438#M17009</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-05-01T18:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to  check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555538#M17011</link>
      <description>&lt;P&gt;Hi Erik,&lt;/P&gt;&lt;P&gt;Thanks for this.Would you please help on creating code for user written node transformation please as i am new to this.&lt;/P&gt;&lt;P&gt;Actually as part of this we need to check the&amp;nbsp;record count of target dataset,if it is "0" then it should trigger e-mail&amp;nbsp; saying "SAS dataset is updated with 0 observations"&lt;/P&gt;&lt;P&gt;if it is not zero then no need to send e-mail please.kindly help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 06:51:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555538#M17011</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2019-05-02T06:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to  check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555540#M17012</link>
      <description>&lt;P&gt;Hello Chris,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please find my answers below&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe you have a number of SAS libraries that contain data sets that you wish to monitor for zero observations?&lt;/P&gt;&lt;P&gt;Is this correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;Yes,we need to be alerted via e-mail in&amp;nbsp;SAS libraries that contain data sets where we have&amp;nbsp;zero observations&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are multiple SAS libraries involved but you do know prior to batch job execution which SAS libraries contain the data sets that need to be monitored for zero observations?&lt;/P&gt;&lt;P&gt;Is this correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;No i do not know prior/After batch job execution which SAS libraries contain the data sets that need to be monitored for zero observations.so only we would need e-mail to be triggered to us with names of data sets saying these are empty so that&amp;nbsp; we can check later on that these are expected to be empty or not&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You wish to trigger a single email message that lists those input/output tables that contain zero observations?&lt;/P&gt;&lt;P&gt;Is this correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;Yes please ,wish to trigger a single email message that lists those input/output tables that contain zero observations&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you wishing to track input tables (tables that will update a target table) for zero observations or are you wishing to track the final updated target tables for zero observations?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;Yes,we wish to&amp;nbsp;track the final updated target tables for zero observations in all SAS DI jobs.some input tables will be acting as taget tables in some other job,so it is basically&amp;nbsp;final target table&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know if you need further clarification and kindly help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks very much.&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 07:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555540#M17012</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2019-05-02T07:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to  check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555541#M17013</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/256123"&gt;@JJP1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I certainly will. I don't know if I can find time this evening, but you will have it before monday.&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 07:15:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555541#M17013</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-05-02T07:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to  check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555545#M17014</link>
      <description>&lt;P&gt;Hi Erik,&lt;/P&gt;&lt;P&gt;Yes,Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 08:34:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555545#M17014</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2019-05-02T08:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to  check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555703#M17023</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/256123"&gt;@JJP1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I recommend the use of a transformation, because it works very well for us. This approach creates a mail for each table, because there is an instance of the transformation in every job we want to monitor that way. We have about 4000 DI Studio jobs in our baily batch, but if everything runs as expected, we don't get empty tables, so we are not bothered with that many mails.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We chose this approach, because our main concern was to make things easy for ETL developers. When they build a job, they just pull the transformation in and conncet it to the table, and then it works. It would be difficult to fulfill your request and get a single mail only, because the jobs runs after different schedules, so not all jobs are in the batch every day, and there has to be a final job that runs after all other jobs to collect the information and send the mail. It could be done, e.g. by coding the transformation to log each job/table in a database, and then find some way to make sure that the job reporting from the data base wasn't run before all other jobs had finished.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried to write a simple transformation code, which is a cut-down version of our transformation. There might be some tricky things in the code if you are new to SAS, but the logical flow should be easy to follow. Note that mail addresses are hard coded and must be changed to something useful in your setup.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't know how to write a user transformation, this is where you start:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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-left" image-alt="usertransform.gif" style="width: 517px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29169i8C3CBCC6D553B5D3/image-size/large?v=v2&amp;amp;px=999" role="button" title="usertransform.gif" alt="usertransform.gif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And here is the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/***********************************************************************************/
/* MailEmptyDS                                                                     */
/*                                                                                 */
/* This transformation checks for zero observations in input data set and sends    */
/* an error mail.                                                                  */
/*                                                                                 */
/* The transformation works only with physical SAS tables (engine = V9 or BASE).   */
/* It is not possible to get record count from SAS Views or other engines, like    */
/* ODBC. In this case - or if the input data set has no physical existence - no    */
/* mail sent, and the transformation ends with a warning.                          */
/*                                                                                 */
/***********************************************************************************/
%macro MailEmptyDS(dummy);
	%local fejlstop libref dsid engnum rc engine path viewexist dsexist rcnt thisjob JobSlutDatetime;

	%put INFO: Check for zero rows in data set &amp;amp;_INPUT.;

	* Mail addresses;
	%let receiver = somebody@yoursite.xx;
	%let from = SAS Batch &amp;lt;batchaccount@yoursite.xx&amp;gt;

	* Get library engine;
	%let libref = %upcase(%scan(&amp;amp;_INPUT,1,%str(.)));
	%let dsid=%sysfunc(open(sashelp.vlibnam(where=(libname="&amp;amp;libref")),i));
	%if (&amp;amp;dsid ^= 0) %then %do;  
		%let engnum=%sysfunc(varnum(&amp;amp;dsid,ENGINE));
		%let rc=%sysfunc(fetch(&amp;amp;dsid));
		%let engine=%sysfunc(getvarc(&amp;amp;dsid,&amp;amp;engnum));
		%let rc= %sysfunc(close(&amp;amp;dsid.));
	%end;
	%put &amp;amp;=engine;

	* Check: is it a V9/BASE library? - else warn/return;
	%if &amp;amp;engine ne V9 and &amp;amp;engine ne BASE %then %do;
		%let path = %sysfunc(PATHNAME(&amp;amp;libref));
		%put WARNING: Library &amp;amp;libref (&amp;amp;path) is not a SAS BASE library - observation count not possible.;
		%let syscc = 4;
		%return;
	%end;

	* Check: Is it a view? - then warn/return;
	%let viewexist = %sysfunc(exist(&amp;amp;_INPUT,VIEW));
	%if &amp;amp;viewexist = 1 %then %do;
		%put WARNING: &amp;amp;_INPUT is a VIEW - observation count not possible.;
		%let syscc = 4;
		%return;
	%end;

	* Check: Does physical data set exist? - else warn/return;
	%let dsexist = %sysfunc(exist(&amp;amp;_INPUT));
	%if &amp;amp;dsexist = 0 %then %do;
		%put WARNING: Data set &amp;amp;_INPUT does not exist;
		%let syscc = 4;
		%return;
	%end;

	* Get observation count;
	%let rcnt = -1;
	%let dsid = %sysfunc(open(&amp;amp;_INPUT));
	%if &amp;amp;dsid %then %do;
		%let rcnt = %sysfunc(attrn(&amp;amp;dsid,NLOBS));
		%let rc = %sysfunc(close(&amp;amp;dsid));
	%end;
	%put &amp;amp;=rcnt;

	* Send mail if zero observations;
	%if &amp;amp;rcnt = 0 %then %do;
		filename outbox email 
			to = "&amp;amp;receiver"
			from="&amp;amp;from"
			subject="Warning - Empty data set created";

		data _null_;
			file outbox;
			put "Warning - Empty data set created";
			put "Table &amp;amp;_INPUT";
			put "Job &amp;amp;etls_jobName";
		run;
		%put INFO: Error mail sent to &amp;amp;receiver;
	%end;
	%else %put INFO: OK - data set &amp;amp;_INPUT has &amp;amp;rcnt observations.;

%mend;
%MailEmptyDS;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 18:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555703#M17023</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-05-02T18:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to  check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555822#M17026</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/256123"&gt;@JJP1&lt;/a&gt;&amp;nbsp;I hope you fully appreciate how much&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12887"&gt;@ErikLund_Jensen&lt;/a&gt;&amp;nbsp;is helping you here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12887"&gt;@ErikLund_Jensen&lt;/a&gt;&amp;nbsp;The following just as an ideas for code extensions.&lt;/P&gt;
&lt;P&gt;1. I believe NLOBS is set to missing for any database table. You're already checking the library engine. Why not adding some logic to then execute a SQL count(*) for any non-SAS table?&lt;/P&gt;
&lt;P&gt;2. DIS also generates some "&amp;amp;input_count" macro variable. Why not allow for multiple source tables and then just add a loop around your current code?&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 01:47:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555822#M17026</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-05-03T01:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to  check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555864#M17027</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the ideas.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to keep it simple, because i didn't want to scare&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/256123"&gt;@JJP1&lt;/a&gt;&amp;nbsp;off with too many new techniques, so please see my code as a "starter". Our transformation has several options:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Minimum acceptable record count with 0 as default.&lt;/LI&gt;
&lt;LI&gt;Error action (abend/warn) with abend as default.&lt;/LI&gt;
&lt;LI&gt;Send Mail (yes/no) - default: yes.&lt;/LI&gt;
&lt;LI&gt;Optional Mail CC.&lt;/LI&gt;
&lt;LI&gt;Optional text to include in the mail.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;We didn't implement SQL record count, because we have a "best practice", where we create data as SAS tables in one job and load/update database tables in the next job. We use the transformation with error action=Abend in jobs creating SAS tables, so the LSF flow fails before the load job runs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The looping idea is very good. I will implement that!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 08:26:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555864#M17027</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-05-03T08:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to  check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555866#M17028</link>
      <description>&lt;P&gt;Thank you so much Erik for helping me .Thanks for code and explanation and thanks for your time Erik.i will start creating the user written transformation.thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 08:45:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555866#M17028</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2019-05-03T08:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to  check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555870#M17029</link>
      <description>&lt;P&gt;HI Erik,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created the user written code transformation job as you suggested and it is working perfectly.&lt;/P&gt;&lt;P&gt;Thanks for your help and i am just trying to understand the code that you written.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 09:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/555870#M17029</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2019-05-03T09:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to  check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/556035#M17032</link>
      <description>&lt;P&gt;Firstly, there is not a specific out-of-the box data integration studio transformation that will satisfy what you are trying to do. I have taken a first stab at producing SAS code that will produce a final output table which contains a row for each table that contains zero observations. This code will work with SAS library engine types as well as non SAS library engine types such as Oracle. I did not find time to write the email portion, but it seems like you have received other responses for that. In any case, my hope is that you will find some use for this code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROGRAM BEGINS:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/***

Program: notify_zero_obs.sas

Description:

Check for 0 observations in tables and notify when found.

***/

options 
   mprint 
   mlogic 
   symbolgen 
;


/* Initialize macro variables */
%let rootDirPath = C:\communities\notify_zero_obs;


/* Initialize test data */

libname a_1 "&amp;amp;rootDirPath.\dir1";
libname a_2 "&amp;amp;rootDirPath.\dir2";
libname b_1 "&amp;amp;rootDirPath.\dir3";


data a_1.cars;
set sashelp.cars;
run;

data a_1.class;
set sashelp.class(obs=0);
run;

data a_2.snacks;
set sashelp.snacks;
run;

data a_2.stocks;
set sashelp.stocks(obs=0);
run;


/* 

Build libname control table 
Notes: 

1. Some type of filtering where clause will be needed.
2. Only keeping variable libname in control table, but more could be selected

*/
proc datasets library=work 
              nolist 
              nowarn memtype = (data);
delete libnameControl;
quit;

proc sql;
   create table work.libnameControl as
   select distinct(libname), engine
   from dictionary.libnames
   where upcase(substr(libname,1,2)) = "A_";
quit;

/* 
 build table control table 

*/
proc datasets library=work 
              nolist 
              nowarn memtype = (data);
delete tableControl;
quit;

/*

CAUTION:
There are timing considerations when using call execute function.
See this blog for timing issues -
https://blogs.sas.com/content/sgf/2017/08/02/call-execute-for-sas-data-driven-programming/

*/

%macro buildTableControl(libname=, engine=);

proc sql;
   create table work.temp as
   select *, "&amp;amp;engine." as engine length=25
   from dictionary.tables
   where upcase(libname) = "&amp;amp;libname.";
quit;

proc append base=work.tableControl
            data=work.temp force;
run;

%mend;


data _null_;
   set work.libnameControl;

   call execute('%buildTableControl(libname=' || strip(libname) || ',' ||
                                    'engine=' || strip(engine)  || ');');
run;


/*

Update the table control table to add
observation count for Non SAS engines such as Oracle.

Note: cannot use call execute to drive update macro.

*/

%macro getObsCount(libname=, memname=);

proc sql noprint;
select count(*) into: obsCount
from &amp;amp;libname..&amp;amp;memname.;
quit;

proc sql;
   update work.tableControl
   set nobs=&amp;amp;obsCount.
   where upcase(libname) = "&amp;amp;libname." and
         upcase(memname) = "&amp;amp;memname.";
quit;

%mend;

proc datasets library=work 
              nolist 
              nowarn memtype = (data);
delete tableControlNonSAS;
quit;

proc sql;
   create table work.tableControlNonSAS as
   select *
   from work.tableControl 
      where upcase(engine) ne "V9";
quit;

/* load macro variables */
data _null_;
set work.tableControlNonSAS end=eof;


call symputx('libname' || strip(put(_n_,best32.)),libname);
call symputx('memname' || strip(put(_n_,best32.)),memname);

if eof then
   call symputx('numTables',strip(put(_n_,best32.)));
run;

%macro run_getObsCount();
%do i=1 %to &amp;amp;numTables.;
   %getObsCount(libname=&amp;amp;&amp;amp;libname&amp;amp;i., memname=&amp;amp;&amp;amp;memname&amp;amp;i.);
%end;
%mend;
%run_getObsCount();


/* subset for zero obs */
data work.zeroObs;
set work.tableControl(where=(nobs=0));
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 May 2019 18:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/556035#M17032</guid>
      <dc:creator>ChrisLysholm</dc:creator>
      <dc:date>2019-05-03T18:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: SAS DI : Job to  check for empty datasets and e-mail all empty datasets</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/556037#M17033</link>
      <description>&lt;P&gt;Additionally, this code could be converted to generated transform, but I have not had time to produce that. Wanted to get you the basic code for the process first.&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 18:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/SAS-DI-Job-to-check-for-empty-datasets-and-e-mail-all-empty/m-p/556037#M17033</guid>
      <dc:creator>ChrisLysholm</dc:creator>
      <dc:date>2019-05-03T18:11:17Z</dc:date>
    </item>
  </channel>
</rss>

