<?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: WHERE IN Table Function not working in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/WHERE-IN-Table-Function-not-working/m-p/830000#M327943</link>
    <description>I think that makes sense, but let me give it a shot. Thanks!</description>
    <pubDate>Tue, 23 Aug 2022 20:44:49 GMT</pubDate>
    <dc:creator>supersasnewbie</dc:creator>
    <dc:date>2022-08-23T20:44:49Z</dc:date>
    <item>
      <title>WHERE IN Table Function not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-IN-Table-Function-not-working/m-p/829986#M327935</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having some issues with running some code, and hoping someone might have insight into what's going on. It's a pretty simple code that I'm running off a corporate database (I believe it's Teradata-based). However, when I run my code using (SELECT xxx from LIST) in the WHERE function, SAS runs for an extremely long time before timing out. However, when I use the same 85 values from LIST (example: 100, 200, 300) in my WHERE function, the query returns my results pretty quickly. I'm trying to troubleshoot this problem, but not seeing any reason for the query to not work. Here's an example for how this query is put together:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;CREATE TABLE MKTLISTING AS&lt;/P&gt;&lt;P&gt;SELECT MKTSTATE, MKTNBR&lt;/P&gt;&lt;P&gt;FROM MKT_TBL&lt;/P&gt;&lt;P&gt;WHERE MKTSTATE in ('NY') /*This results in numeric MKTNBRs 100,200,300*/&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;RUN&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;CREATE TABLE products AS&lt;/P&gt;&lt;P&gt;SELECT C.PRODCD&lt;/P&gt;&lt;P&gt;,C.PRODTYP&lt;/P&gt;&lt;P&gt;,C.PRODMAN&lt;/P&gt;&lt;P&gt;,S.SALESAREA&lt;/P&gt;&lt;P&gt;,S.MKTNBR&lt;/P&gt;&lt;P&gt;FROM PRODTBL C&lt;/P&gt;&lt;P&gt;, SALESTBL S&lt;/P&gt;&lt;P&gt;WHERE C.PRODCD = S.PROD CD&lt;/P&gt;&lt;P&gt;AND S.MKTNBR in (SELECT MKTNBR FROM MKTLISTING) /*Using this causes the query to timeout, but works fine when (100,200,300) is used in place*/&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any clues to why this occurs would be greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 20:14:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-IN-Table-Function-not-working/m-p/829986#M327935</guid>
      <dc:creator>supersasnewbie</dc:creator>
      <dc:date>2022-08-23T20:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE IN Table Function not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-IN-Table-Function-not-working/m-p/829993#M327938</link>
      <description>&lt;P&gt;Your second query is sort of missing a FROM, such as what table source is getting the alias C, so I am surprised that it runs at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, Proc SQL requires a QUIT. When you use Run; SAS is still waiting for a Quit; to finish the procedure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second query might run faster as a JOIN but too much stuff missing to make a suggestion.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 20:01:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-IN-Table-Function-not-working/m-p/829993#M327938</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-08-23T20:01:03Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE IN Table Function not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-IN-Table-Function-not-working/m-p/829996#M327939</link>
      <description>Thanks for the reply. I made a couple of mistakes when moving the query over to the forum. I've adjusted the post to reflect this.</description>
      <pubDate>Tue, 23 Aug 2022 20:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-IN-Table-Function-not-working/m-p/829996#M327939</guid>
      <dc:creator>supersasnewbie</dc:creator>
      <dc:date>2022-08-23T20:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE IN Table Function not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-IN-Table-Function-not-working/m-p/829997#M327940</link>
      <description>&lt;P&gt;My guess is that the list is shipped to the database server but the table being local requires the server data to be downloaded to perform the query. Using a macro variable to contain the list might work better:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
SELECT MKTNBR into :MKTLISTING separated by ","
FROM MKT_TBL
WHERE MKTSTATE in ('NY') ;
QUIT;

proc sql;
CREATE TABLE products AS
SELECT C.PRODCD
,C.PRODTYP
,C.PRODMAN
,S.SALESAREA
,S.MKTNBR
FROM PRODTBL C
, SALESTBL S
WHERE C.PRODCD = S.PRODCD
AND S.MKTNBR in (&amp;amp;MKTLISTING.) 
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Aug 2022 20:29:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-IN-Table-Function-not-working/m-p/829997#M327940</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-08-23T20:29:26Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE IN Table Function not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-IN-Table-Function-not-working/m-p/830000#M327943</link>
      <description>I think that makes sense, but let me give it a shot. Thanks!</description>
      <pubDate>Tue, 23 Aug 2022 20:44:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-IN-Table-Function-not-working/m-p/830000#M327943</guid>
      <dc:creator>supersasnewbie</dc:creator>
      <dc:date>2022-08-23T20:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE IN Table Function not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-IN-Table-Function-not-working/m-p/830011#M327951</link>
      <description>&lt;P&gt;if i understand your code correctly, this might be a bit cleaner for the query optimizer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC SQL;
CREATE TABLE products AS
	SELECT 
		C.PRODCD
		,C.PRODTYP
		,C.PRODMAN
		,S.SALESAREA
		,S.MKTNBR
	FROM 
		PRODTBL C
		INNER JOIN 
		(
		SELECT s.ProdCD
		FROM 
			SALESTBL a
			INNER JOIN MKTLISTING b on a.MKTNBR = b.MKTNBR
		) s ON C.PRODCD = S.PROD CD
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Aug 2022 22:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-IN-Table-Function-not-working/m-p/830011#M327951</guid>
      <dc:creator>utrocketeng</dc:creator>
      <dc:date>2022-08-23T22:55:54Z</dc:date>
    </item>
  </channel>
</rss>

