<?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: Merge sas data set with teraData table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-sas-data-set-with-teraData-table/m-p/896234#M354117</link>
    <description>&lt;P&gt;How many distinct agreement_account_id does your SAS dataset have?&lt;/P&gt;
&lt;P&gt;In reality, are these keys stored as character or numeric?&lt;/P&gt;</description>
    <pubDate>Thu, 28 Sep 2023 12:22:34 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-09-28T12:22:34Z</dc:date>
    <item>
      <title>Merge sas data set with teraData table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-sas-data-set-with-teraData-table/m-p/896194#M354098</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;There is very big table in TeraData and I need to create a query that use this table.&lt;/P&gt;
&lt;P&gt;The query is running on SAS and based on SAS data set and the table in Tera.&lt;/P&gt;
&lt;P&gt;In real the table name in Tera is&amp;nbsp; Tera.&lt;CODE class=" language-sas"&gt;Tera_tbl&amp;nbsp;&amp;nbsp;(But&amp;nbsp;for&amp;nbsp;the&amp;nbsp;code&amp;nbsp;written&amp;nbsp;here&amp;nbsp;I&amp;nbsp;wrote&amp;nbsp;only&amp;nbsp;tera_tbl).&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;The&amp;nbsp;target&amp;nbsp;is&amp;nbsp;to&amp;nbsp;recognize&amp;nbsp;artificial&amp;nbsp;loans.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;The&amp;nbsp;criteria&amp;nbsp;for&amp;nbsp;it&amp;nbsp;is&amp;nbsp;If&amp;nbsp;the&amp;nbsp;loan&amp;nbsp;key&amp;nbsp;has&amp;nbsp;value&amp;nbsp;M14&amp;nbsp;or&amp;nbsp;M15&amp;nbsp;(in&amp;nbsp;tera&amp;nbsp;table)&amp;nbsp;then&amp;nbsp;it&amp;nbsp;is&amp;nbsp;artificial&amp;nbsp;loan.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;What id better way ? Way1 or Way2?&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Or&amp;nbsp;maybe&amp;nbsp;you&amp;nbsp;can&amp;nbsp;show&amp;nbsp;better&amp;nbsp;way&amp;nbsp;to&amp;nbsp;do&amp;nbsp;it?&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data Have;
input Agreement_Account_Id;
cards;
623977145
623570095
111111111
222344444
;
run;

Data Tera_tbl;
input Event_Category_Type_Code $ Agreement_Account_Id;
cards;
M14 623570095
R1 623977145
M0 623570095
M14 623977145
M0 623977145
;
Run;


proc sql;
create table Way1 as
select  a.Agreement_Account_Id,
         max(case when a.Event_Category_Type_Code IN('M14','M15') then 1 else 0 end ) as Ind_artificial_Haamada label='אינדקיטור העמדה מלאכותית'
from Tera as a
inner join  Have  as b
on a.Agreement_Account_Id=b.Agreement_Account_Id
group by a.Agreement_Account_Id
;
quit;


proc sql;
create table Way2 as
select  distinct a.Agreement_Account_Id
from Tera(keep=Event_Category_Type_Code Agreement_Account_Id Where=(Event_Category_Type_Code IN('M14','M15'))) as a
inner join  Have  as b
on a.Agreement_Account_Id=b.Agreement_Account_Id
;
quit;
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 07:08:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-sas-data-set-with-teraData-table/m-p/896194#M354098</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-09-28T07:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: Merge sas data set with teraData table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-sas-data-set-with-teraData-table/m-p/896196#M354099</link>
      <description>&lt;P&gt;If your Teradata table is big and your SAS table small then try and push processing to Teradata. I order to do so you need either to load your SAS table first into Teradata (could be a temporary table) or you need to generate SAS code that creates a where clause with an in operator that just contains all the key values from your small SAS tables (small means here not more than 100000 rows).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could try if DBKEY does the job for you&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/engfedsrv/p0ulrj2wyjwes2n1mgxd6u50l9xm.htm" target="_blank" rel="nofollow noopener noreferrer"&gt;SAS Help Center: DBKEY= Data Set Option&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1695885750531.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88393iDA85A7822EEDA0D8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1695885750531.png" alt="Patrick_0-1695885750531.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If DBKEY doesn't solve the problem for you then have a look into&amp;nbsp;&lt;A title="this&amp;nbsp;very similar discussion" href="https://communities.sas.com/t5/SAS-Programming/Please-help-improve-the-query/m-p/895388#M353763" target="_self"&gt;this&amp;nbsp;very similar discussion&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 07:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-sas-data-set-with-teraData-table/m-p/896196#M354099</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-09-28T07:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: Merge sas data set with teraData table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-sas-data-set-with-teraData-table/m-p/896203#M354103</link>
      <description>&lt;P&gt;Thanks, However I get error&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: Invalid option name DBKEY.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is my code I run&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
create table tbl_artificial_Haamadot as
select  distinct a.Agreement_Account_Id
from TeraData.V0500_1_FINANCIAL_EVENT(keep=Event_Category_Type_Code Agreement_Account_Id Where=(Event_Category_Type_Code IN('M14','M15'))) as a
inner join  Haamadot_DWH_9(dbkey=(Agreement_Account_Id))  as b
on a.Agreement_Account_Id=b.Agreement_Account_Id
group by a.Agreement_Account_Id
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Sep 2023 07:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-sas-data-set-with-teraData-table/m-p/896203#M354103</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-09-28T07:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: Merge sas data set with teraData table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-sas-data-set-with-teraData-table/m-p/896218#M354109</link>
      <description>&lt;P&gt;According to the example in the docu looks like the DBKEY options needs to be on the database table.&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-inline" image-alt="Patrick_0-1695893726962.png" style="width: 1083px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88397i84BA2519385F120A/image-dimensions/1083x171?v=v2" width="1083" height="171" role="button" title="Patrick_0-1695893726962.png" alt="Patrick_0-1695893726962.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;What doesn't make much sense to me is the use of SAS table options like keep on a database table.&lt;/P&gt;
&lt;P&gt;See if below code works for you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table tbl_artificial_Haamadot as
    select  distinct a.Agreement_Account_Id
      from TeraData.V0500_1_FINANCIAL_EVENT(dbkey=(Agreement_Account_Id)) as a
        inner join  Haamadot_DWH_9 as b
          on a.Agreement_Account_Id=b.Agreement_Account_Id
        where a.Event_Category_Type_Code IN ('M14','M15')
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I can't test it so I'm not sure if the DBKEY option will have the desired effect for above code because of the already existing where clause.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 09:46:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-sas-data-set-with-teraData-table/m-p/896218#M354109</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-09-28T09:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: Merge sas data set with teraData table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-sas-data-set-with-teraData-table/m-p/896234#M354117</link>
      <description>&lt;P&gt;How many distinct agreement_account_id does your SAS dataset have?&lt;/P&gt;
&lt;P&gt;In reality, are these keys stored as character or numeric?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 12:22:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-sas-data-set-with-teraData-table/m-p/896234#M354117</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-28T12:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: Merge sas data set with teraData table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-sas-data-set-with-teraData-table/m-p/896270#M354138</link>
      <description>&lt;P&gt;Of course the DB_KEY= option goes on the database table.&amp;nbsp; &amp;nbsp;You are telling SAS to use those variables as the KEY variables for that table so that it does not have to pull the whole table over to SAS before trying to join.&amp;nbsp; It should allow SAS to instead upload the key values from the SAS dataset to the remote database and so only retrieve the observations from the database it needs.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 15:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-sas-data-set-with-teraData-table/m-p/896270#M354138</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-28T15:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: Merge sas data set with teraData table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-sas-data-set-with-teraData-table/m-p/896392#M354192</link>
      <description>They are stored as numeric and there are 50,000 distinct values . Please note that the tera data table is very very big ( maybe 500 millions rows) and in the tera table each agreement_acvount_id can have multiple rows</description>
      <pubDate>Fri, 29 Sep 2023 08:58:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-sas-data-set-with-teraData-table/m-p/896392#M354192</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-09-29T08:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: Merge sas data set with teraData table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-sas-data-set-with-teraData-table/m-p/896414#M354197</link>
      <description>&lt;P&gt;Create code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;

data _null_;
file code;
set have end=done;
if _n_ = 1
then do;
  put 'proc sql;';
  put 'create table want as select agreement_account_id';
  put 'from have where agreement_account_id in (';
  put 'select agreement_account_id from tera where Event_Category_Type_Code in ("M14","M15") and agreement_account_id in (';
end;
if _n_ &amp;gt; 1 then put ',';
put quote(put(agreement_account_id,z10.)); * use suitable format here;
if done then do;
  put ')); quit;'
end;
run;

%inc code;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, for obvious reasons. I would hope that SAS can translate the sub-select and push it to Teradata.&lt;/P&gt;
&lt;P&gt;If not, create explicit pass-through code in a similar manner.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 13:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-sas-data-set-with-teraData-table/m-p/896414#M354197</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-29T13:26:18Z</dc:date>
    </item>
  </channel>
</rss>

