<?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 If data present in any of the tables(key varaibles) then condition as yes else no in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-data-present-in-any-of-the-tables-key-varaibles-then/m-p/514685#M138797</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have asked to check if data present in any of the four tables&amp;nbsp;then populate the condition as Y else N based on the key columns.&lt;/P&gt;&lt;P&gt;How&amp;nbsp;can I achieve it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Nithya&lt;/P&gt;</description>
    <pubDate>Tue, 20 Nov 2018 07:23:22 GMT</pubDate>
    <dc:creator>Nithya18</dc:creator>
    <dc:date>2018-11-20T07:23:22Z</dc:date>
    <item>
      <title>If data present in any of the tables(key varaibles) then condition as yes else no</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-data-present-in-any-of-the-tables-key-varaibles-then/m-p/514685#M138797</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have asked to check if data present in any of the four tables&amp;nbsp;then populate the condition as Y else N based on the key columns.&lt;/P&gt;&lt;P&gt;How&amp;nbsp;can I achieve it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Nithya&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2018 07:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-data-present-in-any-of-the-tables-key-varaibles-then/m-p/514685#M138797</guid>
      <dc:creator>Nithya18</dc:creator>
      <dc:date>2018-11-20T07:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: If data present in any of the tables(key varaibles) then condition as yes else no</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-data-present-in-any-of-the-tables-key-varaibles-then/m-p/514688#M138800</link>
      <description>&lt;P&gt;Hi and welcome to the SAS community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you ask a question like this, you have to be more specific. For example: &lt;EM&gt;"if data present"&lt;/EM&gt;. What data? And what four tables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please be more specific in your requirements. And if you want a full usable code answer, provide example data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2018 07:31:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-data-present-in-any-of-the-tables-key-varaibles-then/m-p/514688#M138800</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-11-20T07:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: If data present in any of the tables(key varaibles) then condition as yes else no</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-data-present-in-any-of-the-tables-key-varaibles-then/m-p/514689#M138801</link>
      <description>Thank you!!&lt;BR /&gt;For Example,&lt;BR /&gt;if data present in any of the cond1,cond2,cond3,cond4 tables and key column is fcl_id,cus_id,app_id. Then need to provide flag as Y else N.&lt;BR /&gt;proc sql;&lt;BR /&gt;connect to Teradata as db(user=xxx pwd='xxx');&lt;BR /&gt;create table cond as&lt;BR /&gt;select * from connection to db(&lt;BR /&gt;select distinct a.*,b.*,c.*,d.*,&lt;BR /&gt;case when fcl_id^=. or cus_id ^=. or app_id^=. then 'Y' else 'N' end as condition&lt;BR /&gt;from cond1 as a&lt;BR /&gt;left join&lt;BR /&gt;cond2 as b&lt;BR /&gt;on a.fcl_id=b.fcl_id and a.cust_id=b.cust_id and a.app_id=b.app_id&lt;BR /&gt;left join&lt;BR /&gt;cond3 as c&lt;BR /&gt;on a.fcl_id=c.fcl_id and a.cust_id=c.cust_id and a.app_id=c.app_id&lt;BR /&gt;left join&lt;BR /&gt;cond4 as d&lt;BR /&gt;on a.fcl_id=c.fcl_id and a.cust_id=c.cust_id and a.app_id=c.app_id&lt;BR /&gt;);&lt;BR /&gt;disconnect from db;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;But it doesn't work. Kindly suggest the best method to accomplish.</description>
      <pubDate>Tue, 20 Nov 2018 08:06:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-data-present-in-any-of-the-tables-key-varaibles-then/m-p/514689#M138801</guid>
      <dc:creator>Nithya18</dc:creator>
      <dc:date>2018-11-20T08:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: If data present in any of the tables(key varaibles) then condition as yes else no</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-data-present-in-any-of-the-tables-key-varaibles-then/m-p/514694#M138803</link>
      <description>&lt;P&gt;Please post test data in the form of a datastep:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;and what you want to see out at the end.&amp;nbsp; Showing some code and saying it doesn't work tells us nothing.&amp;nbsp; We need to be able to see inputs/outputs to have any idea of what is going on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On your code, I strongly doubt that is the best solution.&amp;nbsp; You are first off selecting&amp;nbsp;all columns from all four tables, e.g. a.*.&amp;nbsp; That cannot be what you want is it?&amp;nbsp; Second you are using left joins, so only data which appears in the preceeding data will appear in the output.&amp;nbsp; So only data in B which has a match in a on the clause will appear, again I highly doubt this is what you mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I would suggest is that you create datasets of the data you actually want, then do a simple merge:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  connect to teradata as db(...);
  create table a as (select fcl_id,cust_id,app_id,"A" as tab1 from cond1 order by fcl_id,cust_id,app_id);
  create table b as (select fcl_id,cust_id,app_id,"B" as tab2 from cond2 order by fcl_id,cust_id,app_id);
  create table c as (select fcl_id,cust_id,app_id,"C" as tab3 from cond3 order by fcl_id,cust_id,app_id);
  create table d as (select fcl_id,cust_id,app_id,"D" as tab4 from cond4 order by fcl_id,cust_id,app_id);
  disconnect from db;
quit;

data want;
  merge a b c d;
  by fcl_id cust_id app_id;
run;&lt;/PRE&gt;
&lt;P&gt;You will then have a complete list of the merged id variables, and four columns tab1-4 which show presence in each table.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2018 08:52:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-data-present-in-any-of-the-tables-key-varaibles-then/m-p/514694#M138803</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-20T08:52:18Z</dc:date>
    </item>
  </channel>
</rss>

