<?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: Abort job if source and compare tables are different - SAS DI Studio 4.9 in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Abort-job-if-source-and-compare-tables-are-different-SAS-DI/m-p/349064#M10374</link>
    <description>&lt;P&gt;I haven't used this transformation either so just answering your question how to retrieve the number of rows from a SAS table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could always do a SQL count(*) but with SAS tables the number of rows in a table is also a table attribute which you can query without the need to pass through the actual data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* option 1 */
data _null_;
  call symputx('NobsInTable1',NumObsInTable);
  stop;
  set sashelp.class nobs=NumObsInTable;
run;
%put &amp;amp;=NobsInTable1;

/* option 2 */
proc sql noprint;
  select nobs into :NobsInTable2
  from dictionary.tables
  where libname='SASHELP' and memname='CLASS'
  ;
quit;
%put &amp;amp;=NobsInTable2;

/* Extended option 2: rowcount sum for multiple tables */
proc sql noprint;
  select sum(nobs) into :NobsInTableN
  from dictionary.tables
  where libname='SASHELP' and memname in ('CLASS','COMPANY')
  ;
quit;
%put &amp;amp;=NobsInTableN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Apr 2017 11:56:35 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2017-04-11T11:56:35Z</dc:date>
    <item>
      <title>Abort job if source and compare tables are different - SAS DI Studio 4.9</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Abort-job-if-source-and-compare-tables-are-different-SAS-DI/m-p/349045#M10371</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to compare the result of two queries that should return the same results.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using the compare table transformation to compare the resulting tables and I want the Job to abort in case the tables are different, i.e. if any of the tables besides the 'unchanged records' table has any records.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea of how to do this?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 14:30:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Abort-job-if-source-and-compare-tables-are-different-SAS-DI/m-p/349045#M10371</guid>
      <dc:creator>Ricardo_Neves</dc:creator>
      <dc:date>2017-04-11T14:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: Abort job if source and compare tables are different - SAS DI Studio 4.9</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Abort-job-if-source-and-compare-tables-are-different-SAS-DI/m-p/349051#M10372</link>
      <description>&lt;P&gt;I haven't used that particular transformation, neither have&amp;nbsp;access to DIS at the moment, so this will be a "paper" reply.&lt;/P&gt;
&lt;P&gt;Depending on how the "other tables" are created, you would migh be able to use Status Handling (data modified...?).&lt;/P&gt;
&lt;P&gt;Another option is to have a post process/user&amp;nbsp;written transformation that checks for no of records in &amp;amp;SYSLAST (or&amp;nbsp;whatever&amp;nbsp;works in the current situation).&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 10:51:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Abort-job-if-source-and-compare-tables-are-different-SAS-DI/m-p/349051#M10372</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-04-11T10:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: Abort job if source and compare tables are different - SAS DI Studio 4.9</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Abort-job-if-source-and-compare-tables-are-different-SAS-DI/m-p/349053#M10373</link>
      <description>&lt;P&gt;This transformation connects 2 tables (one as source and another as a compare table) through a key column&amp;nbsp;(in this case i'm using a date) and compares the columns I designate. Then it populates 4 tables: New records, Changed records, Unchanged records, Missing records.&lt;BR /&gt;&lt;BR /&gt;There is no Status Handling Option in this transformation and usually the status handling only has options to abort if the table is empty, not if it is not empty...&lt;BR /&gt;&lt;BR /&gt;I'm sorry but I'm fairly new to SAS, how would I verify if the tables are empty and abort if not in a user written code?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 11:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Abort-job-if-source-and-compare-tables-are-different-SAS-DI/m-p/349053#M10373</guid>
      <dc:creator>Ricardo_Neves</dc:creator>
      <dc:date>2017-04-11T11:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: Abort job if source and compare tables are different - SAS DI Studio 4.9</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Abort-job-if-source-and-compare-tables-are-different-SAS-DI/m-p/349064#M10374</link>
      <description>&lt;P&gt;I haven't used this transformation either so just answering your question how to retrieve the number of rows from a SAS table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could always do a SQL count(*) but with SAS tables the number of rows in a table is also a table attribute which you can query without the need to pass through the actual data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* option 1 */
data _null_;
  call symputx('NobsInTable1',NumObsInTable);
  stop;
  set sashelp.class nobs=NumObsInTable;
run;
%put &amp;amp;=NobsInTable1;

/* option 2 */
proc sql noprint;
  select nobs into :NobsInTable2
  from dictionary.tables
  where libname='SASHELP' and memname='CLASS'
  ;
quit;
%put &amp;amp;=NobsInTable2;

/* Extended option 2: rowcount sum for multiple tables */
proc sql noprint;
  select sum(nobs) into :NobsInTableN
  from dictionary.tables
  where libname='SASHELP' and memname in ('CLASS','COMPANY')
  ;
quit;
%put &amp;amp;=NobsInTableN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 11:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Abort-job-if-source-and-compare-tables-are-different-SAS-DI/m-p/349064#M10374</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-04-11T11:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Abort job if source and compare tables are different - SAS DI Studio 4.9</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Abort-job-if-source-and-compare-tables-are-different-SAS-DI/m-p/349144#M10376</link>
      <description>&lt;P&gt;I think I solved it but I had to use a User Written transformation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I'm using, in case someone comes across a similar problem.&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;data _null_;
  if eof then
    do;
     
     put 'NOTE: EOF - DATASET vazio';
    end;
	else do;
		call symput('dsempty',1);
	end;
  set &amp;amp;_input1 end=eof;
run;

data _null_;
  if eof then
    do;
     
     put 'NOTE: EOF - DATASET vazio';
    end;
	else do;
		call symput('dsempty',1);
	end;
  set &amp;amp;_input2 end=eof;
run;

data _null_;
  if eof then
    do;
     
     put 'NOTE: EOF - DATASET vazio';
    end;
	else do;
		call symput('dsempty',1);
	end;
  set &amp;amp;_input3 end=eof;
run;

%macro Compare;&lt;BR /&gt; %if &amp;amp;dsempty = 1 %then %do;&lt;BR /&gt; %abort;&lt;BR /&gt; %end;&lt;BR /&gt;%mend;&lt;BR /&gt;&lt;BR /&gt;
%Compare;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 14:41:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Abort-job-if-source-and-compare-tables-are-different-SAS-DI/m-p/349144#M10376</guid>
      <dc:creator>Ricardo_Neves</dc:creator>
      <dc:date>2017-04-11T14:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: Abort job if source and compare tables are different - SAS DI Studio 4.9</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Abort-job-if-source-and-compare-tables-are-different-SAS-DI/m-p/349287#M10388</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132854"&gt;@Ricardo_Neves&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;You're still having a full pass through the data which is not necessary. Here an alternative option which doesn't need to process the data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1 test2 test3;
/*  stop;*/
  set sashelp.class;
run;
%let _input1=test1;
%let _input2=test2;
%let _input3=test3;

/* Extended option 2: rowcount sum for multiple tables */
%let NobsInTables=0;
proc sql noprint feedback;
  select sum(nobs) into :NobsInTables
  from dictionary.tables
  where 
    libname="%scan(WORK.%upcase(&amp;amp;_input1),-2,.)"
    and memname in 
                  (
                    "%scan(%upcase(&amp;amp;_input1),-1,.)",
                    "%scan(%upcase(&amp;amp;_input2),-1,.)",
                    "%scan(%upcase(&amp;amp;_input3),-1,.)"
                    )
  ;
quit;

%put &amp;amp;=NobsInTables;

data _null_;
  if &amp;amp;NobsInTables &amp;lt; 1 then
    do;
      put 'Tables not identical';
      put 'Aborting job...., Aborting job....';
      abort return 10;    
    end;
  stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 23:03:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Abort-job-if-source-and-compare-tables-are-different-SAS-DI/m-p/349287#M10388</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-04-11T23:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: Abort job if source and compare tables are different - SAS DI Studio 4.9</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Abort-job-if-source-and-compare-tables-are-different-SAS-DI/m-p/354030#M10587</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;the&amp;nbsp;first time I tryed your solution it didin't work and I didn't really understand why, but now I understood your code better and realised it has to be&lt;/P&gt;&lt;PRE&gt;data _null_;
  if &amp;amp;NobsInTables &amp;gt; 0 then
    do;
      put 'Tables not identical';
      put 'Aborting job...., Aborting job....';
      abort return 10;    
    end;
  stop;
run;&lt;/PRE&gt;&lt;P&gt;because I want to abort if there are any observations in the table.&lt;/P&gt;&lt;P&gt;This really is a better option. Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2017 10:50:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Abort-job-if-source-and-compare-tables-are-different-SAS-DI/m-p/354030#M10587</guid>
      <dc:creator>Ricardo_Neves</dc:creator>
      <dc:date>2017-04-27T10:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: Abort job if source and compare tables are different - SAS DI Studio 4.9</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Abort-job-if-source-and-compare-tables-are-different-SAS-DI/m-p/354361#M10611</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132854"&gt;@Ricardo_Neves&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Good that it worked for you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 08:47:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Abort-job-if-source-and-compare-tables-are-different-SAS-DI/m-p/354361#M10611</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-04-28T08:47:57Z</dc:date>
    </item>
  </channel>
</rss>

