<?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 Find an Id which can be in multiple tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-an-Id-which-can-be-in-multiple-tables/m-p/39874#M8080</link>
    <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
Im building a Stored Process and i have like an ID which can be in 4 tables.&lt;BR /&gt;
&lt;BR /&gt;
If it is in table A, i want to get the data from table A.&lt;BR /&gt;
If ti is in table B, i want to get the data from table B,&lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
at the moment i'm doing the following but it takes a long time, not efficient enough&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/* See which type of data it is - in which EDC table do i find it */&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint; select count(*) into:NumberEdcThick from RF300L3.edc_thick where col_ins_id = "&amp;amp;sel_col_ins_id";quit;&lt;BR /&gt;
%put &amp;amp;NumberEdcThick;&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint; &lt;BR /&gt;
select count(*) into:NumberEdcCd from RF300L3.edc_cd where col_ins_id = "&amp;amp;sel_col_ins_id";quit;&lt;BR /&gt;
%put &amp;amp;NumberEdcCd;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint; select count(*) into:NumberEdcTxrF from RF300L3.edc_txrf where col_ins_id = "&amp;amp;sel_col_ins_id";quit;&lt;BR /&gt;
%put &amp;amp;NumberEdcTxrF;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%macro getData;&lt;BR /&gt;
%if &amp;amp;NumberEdcCd &amp;gt; 0 %then %do;&lt;BR /&gt;
data out_table;&lt;BR /&gt;
set RF300L3.edc_cd;&lt;BR /&gt;
where col_ins_id = "&amp;amp;sel_col_ins_id";&lt;BR /&gt;
CALL SYMPUT('TYPE', 'EDC_CD - Format');&lt;BR /&gt;
run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %if &amp;amp;NumberEdcThick &amp;gt; 0 %then %do;&lt;BR /&gt;
data out_table;&lt;BR /&gt;
set RF300L3.edc_thick;&lt;BR /&gt;
where col_ins_id = "&amp;amp;sel_col_ins_id";&lt;BR /&gt;
CALL SYMPUT('TYPE', 'THICK - Format');&lt;BR /&gt;
run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %if &amp;amp;NumberEdcTxrF &amp;gt; 0 %then %do;&lt;BR /&gt;
data out_table;&lt;BR /&gt;
set RF300L3.edc_txrf;&lt;BR /&gt;
where col_ins_id = "&amp;amp;sel_col_ins_id";&lt;BR /&gt;
CALL SYMPUT('TYPE', 'TXRF - Format');&lt;BR /&gt;
run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %do;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
	CALL SYMPUT('TYPE', 'General - Format');&lt;BR /&gt;
	run;&lt;BR /&gt;
%extract_edc_full(pInProcess WaferId User_id State Slot ROW_ID ProcessRecipe ProcessPlan PmProcedure MeasRecipe &lt;BR /&gt;
					MeasKey MainTool LotId LimitsKey InspectionTool Facility DuploWaferId Datim CustomKey &lt;BR /&gt;
					ChecklistActivityId CSIM_TIMESTAMP COL_INS_ID, out_table);&lt;BR /&gt;
					%end;&lt;BR /&gt;
%mend;&lt;BR /&gt;
%getData;</description>
    <pubDate>Tue, 29 Mar 2011 09:21:49 GMT</pubDate>
    <dc:creator>Filipvdr</dc:creator>
    <dc:date>2011-03-29T09:21:49Z</dc:date>
    <item>
      <title>Find an Id which can be in multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-an-Id-which-can-be-in-multiple-tables/m-p/39874#M8080</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
Im building a Stored Process and i have like an ID which can be in 4 tables.&lt;BR /&gt;
&lt;BR /&gt;
If it is in table A, i want to get the data from table A.&lt;BR /&gt;
If ti is in table B, i want to get the data from table B,&lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
at the moment i'm doing the following but it takes a long time, not efficient enough&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/* See which type of data it is - in which EDC table do i find it */&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint; select count(*) into:NumberEdcThick from RF300L3.edc_thick where col_ins_id = "&amp;amp;sel_col_ins_id";quit;&lt;BR /&gt;
%put &amp;amp;NumberEdcThick;&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint; &lt;BR /&gt;
select count(*) into:NumberEdcCd from RF300L3.edc_cd where col_ins_id = "&amp;amp;sel_col_ins_id";quit;&lt;BR /&gt;
%put &amp;amp;NumberEdcCd;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint; select count(*) into:NumberEdcTxrF from RF300L3.edc_txrf where col_ins_id = "&amp;amp;sel_col_ins_id";quit;&lt;BR /&gt;
%put &amp;amp;NumberEdcTxrF;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%macro getData;&lt;BR /&gt;
%if &amp;amp;NumberEdcCd &amp;gt; 0 %then %do;&lt;BR /&gt;
data out_table;&lt;BR /&gt;
set RF300L3.edc_cd;&lt;BR /&gt;
where col_ins_id = "&amp;amp;sel_col_ins_id";&lt;BR /&gt;
CALL SYMPUT('TYPE', 'EDC_CD - Format');&lt;BR /&gt;
run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %if &amp;amp;NumberEdcThick &amp;gt; 0 %then %do;&lt;BR /&gt;
data out_table;&lt;BR /&gt;
set RF300L3.edc_thick;&lt;BR /&gt;
where col_ins_id = "&amp;amp;sel_col_ins_id";&lt;BR /&gt;
CALL SYMPUT('TYPE', 'THICK - Format');&lt;BR /&gt;
run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %if &amp;amp;NumberEdcTxrF &amp;gt; 0 %then %do;&lt;BR /&gt;
data out_table;&lt;BR /&gt;
set RF300L3.edc_txrf;&lt;BR /&gt;
where col_ins_id = "&amp;amp;sel_col_ins_id";&lt;BR /&gt;
CALL SYMPUT('TYPE', 'TXRF - Format');&lt;BR /&gt;
run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %do;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
	CALL SYMPUT('TYPE', 'General - Format');&lt;BR /&gt;
	run;&lt;BR /&gt;
%extract_edc_full(pInProcess WaferId User_id State Slot ROW_ID ProcessRecipe ProcessPlan PmProcedure MeasRecipe &lt;BR /&gt;
					MeasKey MainTool LotId LimitsKey InspectionTool Facility DuploWaferId Datim CustomKey &lt;BR /&gt;
					ChecklistActivityId CSIM_TIMESTAMP COL_INS_ID, out_table);&lt;BR /&gt;
					%end;&lt;BR /&gt;
%mend;&lt;BR /&gt;
%getData;</description>
      <pubDate>Tue, 29 Mar 2011 09:21:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-an-Id-which-can-be-in-multiple-tables/m-p/39874#M8080</guid>
      <dc:creator>Filipvdr</dc:creator>
      <dc:date>2011-03-29T09:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Find an Id which can be in multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-an-Id-which-can-be-in-multiple-tables/m-p/39875#M8081</link>
      <description>It looks like you want to set macro variable value when dataset is non-empty.&lt;BR /&gt;
You can use dictionary table ( dictionary.tables ) to get the number of obs for special tables.&lt;BR /&gt;
Maybe will save your some time.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Wed, 30 Mar 2011 03:43:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-an-Id-which-can-be-in-multiple-tables/m-p/39875#M8081</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-03-30T03:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: Find an Id which can be in multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-an-Id-which-can-be-in-multiple-tables/m-p/39876#M8082</link>
      <description>Consider adding an index on column "col_ins_id" on your 3 input tables.&lt;BR /&gt;
&lt;BR /&gt;
In your example you will always be reading first 3 tables + 1 table, another approach would in worst case only read through max 3 tables. If you first query the most likely table, then the other 2 tables might not be used that often. Or you could change the order, so the smallest table is first. Perhaps adding a KEEP statement, when reading would improve the performance (depending on your data)&lt;BR /&gt;
&lt;BR /&gt;
/* See which type of data it is - in which EDC table do i find it */&lt;BR /&gt;
&lt;BR /&gt;
%macro getData;&lt;BR /&gt;
  %let type=;&lt;BR /&gt;
  data out_table;&lt;BR /&gt;
   set RF300L3.edc_cd end=theend;&lt;BR /&gt;
   where col_ins_id = "&amp;amp;sel_col_ins_id";&lt;BR /&gt;
   if theend then CALL SYMPUT('TYPE', 'EDC_CD - Format');&lt;BR /&gt;
  run;&lt;BR /&gt;
 %if "&amp;amp;type" ne "" %then %do;&lt;BR /&gt;
   data out_table;&lt;BR /&gt;
    set RF300L3.edc_thick end=theend;&lt;BR /&gt;
    where col_ins_id = "&amp;amp;sel_col_ins_id";&lt;BR /&gt;
    if theend then CALL SYMPUT('TYPE', 'THICK - Format');&lt;BR /&gt;
   run;&lt;BR /&gt;
 %end;&lt;BR /&gt;
 %else %if "&amp;amp;type" ne "" %then %do;&lt;BR /&gt;
   data out_table;&lt;BR /&gt;
    set RF300L3.edc_txrf end=theend;&lt;BR /&gt;
    where col_ins_id = "&amp;amp;sel_col_ins_id";&lt;BR /&gt;
    if theend then CALL SYMPUT('TYPE', 'TXRF - Format');&lt;BR /&gt;
   run;&lt;BR /&gt;
 %end;&lt;BR /&gt;
 %else %do;&lt;BR /&gt;
  data _null_;&lt;BR /&gt;
   CALL SYMPUT('TYPE', 'General - Format');&lt;BR /&gt;
  run;&lt;BR /&gt;
  %extract_edc_full(pInProcess WaferId User_id State Slot ROW_ID ProcessRecipe ProcessPlan PmProcedure MeasRecipe &lt;BR /&gt;
  MeasKey MainTool LotId LimitsKey InspectionTool Facility DuploWaferId Datim CustomKey &lt;BR /&gt;
  ChecklistActivityId CSIM_TIMESTAMP COL_INS_ID, out_table);&lt;BR /&gt;
 %end;&lt;BR /&gt;
%mend;&lt;BR /&gt;
%getData;</description>
      <pubDate>Wed, 30 Mar 2011 13:08:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-an-Id-which-can-be-in-multiple-tables/m-p/39876#M8082</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2011-03-30T13:08:10Z</dc:date>
    </item>
  </channel>
</rss>

