<?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: Check if value exists in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-if-value-exists/m-p/628819#M185871</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/314650"&gt;@adspc&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have one main table with keys and I want to check if those keys exists in other tables. Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;MAIN TABLE&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;keys
----
1
2
3 &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;OTHERS&lt;/EM&gt; (85 tables)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;TABLE 1&lt;/STRONG&gt;&lt;BR /&gt;key  date
---  ----------  
1    2020/01/01   &lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;TABLE 2&lt;/STRONG&gt;&lt;BR /&gt;key  date
---  ---------  
2    2020/01/02&lt;BR /&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; 2020/01/02&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;TABLE 3&lt;/STRONG&gt;&lt;BR /&gt;key  date
---  ---------  
1    2020/01/03&lt;BR /&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; 2020/01/03&lt;BR /&gt;&lt;BR /&gt;etc...&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With 3 tables was ok. I did:&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;PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_DATA AS 
   SELECT t1.A, 
          t2.B, 
          t3.B AS B1, 
          t4.B AS B2
      FROM WORK.DATA t1
           LEFT JOIN WORK.TB1 t2 ON (t1.A = t2.A)
           LEFT JOIN WORK.TB2 t3 ON (t1.A = t3.A)
           LEFT JOIN WORK.TB3 t4 ON (t1.A = t4.A);
QUIT;&lt;/CODE&gt;&lt;/PRE&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;PRE&gt;&lt;STRONG&gt;RESULT&lt;/STRONG&gt;&lt;BR /&gt;A    B           B1          B2         
---  ----------  ----------  ----------
1    2020/01/01              2020/01/03&lt;BR /&gt;2                2020/01/02&lt;BR /&gt;3&amp;nbsp;&amp;nbsp;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2020/01/02&amp;nbsp;&amp;nbsp;2020/01/03&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem here it's 85 tables that I need to do that and 7 millions keys! So 85 columns with 7 millions rows. And I'm getting space error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a better approach to do this? Also is it possible to make the header as that date and fill with 1 or 0. For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;EXPECTED&lt;/STRONG&gt;
A    2020/01/01  2020/01/03  2020/01/02         
---  ----------  ----------  ----------
1    1                       1
2                1
3                1   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would suggest supplying some reasoning behind why you need to know "if those keys exist in other tables".&lt;/P&gt;
&lt;P&gt;Bringing lots of other variables doesn't really help answer the base question and combining values from multiple tables across as your are doing likely makes things much more complicated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the only other variable of interest is always called date I would suggest making temp data sets that contained&lt;BR /&gt;Key Table Date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which could likely be created using call execute with dictionary.tables to create the code to make them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then if needed append all of the temp tables and write a report.&lt;/P&gt;</description>
    <pubDate>Mon, 02 Mar 2020 16:28:57 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-03-02T16:28:57Z</dc:date>
    <item>
      <title>Check if value exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-value-exists/m-p/628802#M185866</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have one main table with keys and I want to check if those keys exists in other tables. Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;MAIN TABLE&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;keys
----
1
2
3 &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;OTHERS&lt;/EM&gt; (85 tables)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;TABLE 1&lt;/STRONG&gt;&lt;BR /&gt;key  date
---  ----------  
1    2020/01/01   &lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;TABLE 2&lt;/STRONG&gt;&lt;BR /&gt;key  date
---  ---------  
2    2020/01/02&lt;BR /&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; 2020/01/02&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;TABLE 3&lt;/STRONG&gt;&lt;BR /&gt;key  date
---  ---------  
1    2020/01/03&lt;BR /&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; 2020/01/03&lt;BR /&gt;&lt;BR /&gt;etc...&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With 3 tables was ok. I did:&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;PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_DATA AS 
   SELECT t1.A, 
          t2.B, 
          t3.B AS B1, 
          t4.B AS B2
      FROM WORK.DATA t1
           LEFT JOIN WORK.TB1 t2 ON (t1.A = t2.A)
           LEFT JOIN WORK.TB2 t3 ON (t1.A = t3.A)
           LEFT JOIN WORK.TB3 t4 ON (t1.A = t4.A);
QUIT;&lt;/CODE&gt;&lt;/PRE&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;PRE&gt;&lt;STRONG&gt;RESULT&lt;/STRONG&gt;&lt;BR /&gt;A    B           B1          B2         
---  ----------  ----------  ----------
1    2020/01/01              2020/01/03&lt;BR /&gt;2                2020/01/02&lt;BR /&gt;3&amp;nbsp;&amp;nbsp;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2020/01/02&amp;nbsp;&amp;nbsp;2020/01/03&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem here it's 85 tables that I need to do that and 7 millions keys! So 85 columns with 7 millions rows. And I'm getting space error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a better approach to do this? Also is it possible to make the header as that date and fill with 1 or 0. For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;EXPECTED&lt;/STRONG&gt;
A    2020/01/01  2020/01/03  2020/01/02         
---  ----------  ----------  ----------
1    1                       1
2                1
3                1   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2020 15:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-value-exists/m-p/628802#M185866</guid>
      <dc:creator>adspc</dc:creator>
      <dc:date>2020-03-02T15:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: Check if value exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-value-exists/m-p/628819#M185871</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/314650"&gt;@adspc&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have one main table with keys and I want to check if those keys exists in other tables. Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;MAIN TABLE&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;keys
----
1
2
3 &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;OTHERS&lt;/EM&gt; (85 tables)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;TABLE 1&lt;/STRONG&gt;&lt;BR /&gt;key  date
---  ----------  
1    2020/01/01   &lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;TABLE 2&lt;/STRONG&gt;&lt;BR /&gt;key  date
---  ---------  
2    2020/01/02&lt;BR /&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; 2020/01/02&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;TABLE 3&lt;/STRONG&gt;&lt;BR /&gt;key  date
---  ---------  
1    2020/01/03&lt;BR /&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; 2020/01/03&lt;BR /&gt;&lt;BR /&gt;etc...&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With 3 tables was ok. I did:&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;PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_DATA AS 
   SELECT t1.A, 
          t2.B, 
          t3.B AS B1, 
          t4.B AS B2
      FROM WORK.DATA t1
           LEFT JOIN WORK.TB1 t2 ON (t1.A = t2.A)
           LEFT JOIN WORK.TB2 t3 ON (t1.A = t3.A)
           LEFT JOIN WORK.TB3 t4 ON (t1.A = t4.A);
QUIT;&lt;/CODE&gt;&lt;/PRE&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;PRE&gt;&lt;STRONG&gt;RESULT&lt;/STRONG&gt;&lt;BR /&gt;A    B           B1          B2         
---  ----------  ----------  ----------
1    2020/01/01              2020/01/03&lt;BR /&gt;2                2020/01/02&lt;BR /&gt;3&amp;nbsp;&amp;nbsp;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2020/01/02&amp;nbsp;&amp;nbsp;2020/01/03&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem here it's 85 tables that I need to do that and 7 millions keys! So 85 columns with 7 millions rows. And I'm getting space error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a better approach to do this? Also is it possible to make the header as that date and fill with 1 or 0. For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;EXPECTED&lt;/STRONG&gt;
A    2020/01/01  2020/01/03  2020/01/02         
---  ----------  ----------  ----------
1    1                       1
2                1
3                1   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would suggest supplying some reasoning behind why you need to know "if those keys exist in other tables".&lt;/P&gt;
&lt;P&gt;Bringing lots of other variables doesn't really help answer the base question and combining values from multiple tables across as your are doing likely makes things much more complicated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the only other variable of interest is always called date I would suggest making temp data sets that contained&lt;BR /&gt;Key Table Date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which could likely be created using call execute with dictionary.tables to create the code to make them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then if needed append all of the temp tables and write a report.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2020 16:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-value-exists/m-p/628819#M185871</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-02T16:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: Check if value exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-value-exists/m-p/628865#M185890</link>
      <description>&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;that providing more clear logic and possibly a different approach could get you to the final destination.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You final output tables are not really in a format that I would advise, as they don't work well in SAS; and so I would advise you have one very long data set rather than the wider data sets you are asking for. Variables Key Table Date — oh wait,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;already said that. If you absolutely need dates as the columns as in your example, that can be done via PROC REPORT, don't assume that you have to have a SAS data set organized that way, you want a long SAS data set, not a wide SAS data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also think SQL is completely the wrong tool here, as handling 85 tables will be a lot of coding. Something more along these lines would be better, in my opinion:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set table:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; Not a lot of coding at all.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2020 18:14:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-value-exists/m-p/628865#M185890</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-02T18:14:52Z</dc:date>
    </item>
  </channel>
</rss>

