<?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: Pro SQL Import merge Quickly in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Pro-SQL-Import-merge-Quickly/m-p/855661#M42095</link>
    <description>&lt;P&gt;If just have 60 values then put them into a macro variable (macro variables can hold up to 64K bytes) and use that to generate the WHERE clause.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct id 
  into :idlist separated by ' ' 
  from ID
;
create table want as
  select w.*
  from database.tableimport w
  where w.indicator = "Y"  and  w.type IN (2 3)
    and w.id IN (&amp;amp;idlist)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the ID variable is character then add quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct quote(trim(id))
  into :idlist separated by ' ' 
  from ID
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the quotes to be single quote characters instead of double quote characters so you can use them in explicit passthru SQL then add the second argument to the QUOTE() function.&amp;nbsp; In that case you will probably also have to use comma as the delimiter instead of space.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct quote(trim(id),"'")
  into :idlist separated by ',' 
  from ID
;
connect using database ;
create table want as
  select * from connection to database
(select w.* 
  from schema.tableimport w
  where w.indicator = 'Y'  and  w.type IN (2,3)
    and w.id IN (&amp;amp;idlist)
)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 25 Jan 2023 22:23:45 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-01-25T22:23:45Z</dc:date>
    <item>
      <title>Pro SQL Import merge Quickly</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Pro-SQL-Import-merge-Quickly/m-p/855610#M42093</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I cannot disclose actual examples of data being pulled. Small examples of fake data will be used below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Currently, I am trying to take a table of 60 IDs and pull out those IDs' connection codes on an import from data tables of 100K+ lines. I am trying to find a way faster way to do this. Currently, it takes 30+ minutes to do this pull.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I DO NOT want to import the database as a whole because this takes hours.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried the codes below and all still take 30 mins.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I manually put the 60 IDs in for w.id IN () it runs in a matter of 45 seconds.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table want as
select w.*
From database.tableimport w

where w.indicator = "Y"  and  w.type IN (2 3)
and w.id IN (select id 
from IDList)
;
 quit;
&lt;/PRE&gt;
&lt;PRE&gt;proc sql;
create table want as
select w.*,
id.ID
From ID id
Left Join database.tableimport w on w.id = id.ID
where w.Indicator = "Y"  and w.type IN (2 3);
 quit;
&lt;/PRE&gt;
&lt;PRE&gt;proc sql;
create table want as
select w.*,
id.ID
From ID id
Left Join database.tableimport w on id.ID=w.id 
where w.Indicator = "Y"  and w.type IN (2 3);
 quit;&lt;/PRE&gt;
&lt;PRE&gt;proc sql;
create table want as
select w.*,
id.ID
From ID id
Join database.tableimport w on id.ID=w.id 
where w.Indicator = "Y"  and w.type IN (2 3);
 quit;&lt;/PRE&gt;
&lt;PRE&gt;proc sql;
create table want as
select w.*,
id.ID
From ID id
Join database.tableimport w on w.id = id.ID
where w.Indicator = "Y"  and w.type IN (2 3);
 quit;&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;P&gt;Any advice is much appreciated&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, the start table would look like&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="90"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="90"&gt;ID&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;953252453&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and Final Table would look like&lt;/P&gt;
&lt;TABLE width="594"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="90"&gt;ID&lt;/TD&gt;
&lt;TD width="298"&gt;Indicator&amp;nbsp;&lt;/TD&gt;
&lt;TD width="142"&gt;Type&lt;/TD&gt;
&lt;TD width="64"&gt;connection&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;asdfa&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;afsdfae&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;avsdfa&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;dfad&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;953252453&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;adfawede&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;sadf&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;asdfa&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;953252453&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;asdfaedae&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2023 18:37:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Pro-SQL-Import-merge-Quickly/m-p/855610#M42093</guid>
      <dc:creator>ccaudillo100</dc:creator>
      <dc:date>2023-01-25T18:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: Pro SQL Import merge Quickly</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Pro-SQL-Import-merge-Quickly/m-p/855652#M42094</link>
      <description>&lt;P&gt;Some details that may be important.&lt;/P&gt;
&lt;P&gt;Is your Database.tableimport a native SAS dataset or is that a link to an external database?&lt;/P&gt;
&lt;P&gt;If it is an external database then you may want to share how you are doing that link as options on that may be what is needed.&lt;/P&gt;
&lt;P&gt;Also you need to consider how good/fast your connection to that database might be. If the DB server is busy you may just have to put up with how long it processes your request but there might be options that help optimize performance. But we need to see what you are using.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2023 20:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Pro-SQL-Import-merge-Quickly/m-p/855652#M42094</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-01-25T20:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: Pro SQL Import merge Quickly</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Pro-SQL-Import-merge-Quickly/m-p/855661#M42095</link>
      <description>&lt;P&gt;If just have 60 values then put them into a macro variable (macro variables can hold up to 64K bytes) and use that to generate the WHERE clause.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct id 
  into :idlist separated by ' ' 
  from ID
;
create table want as
  select w.*
  from database.tableimport w
  where w.indicator = "Y"  and  w.type IN (2 3)
    and w.id IN (&amp;amp;idlist)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the ID variable is character then add quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct quote(trim(id))
  into :idlist separated by ' ' 
  from ID
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the quotes to be single quote characters instead of double quote characters so you can use them in explicit passthru SQL then add the second argument to the QUOTE() function.&amp;nbsp; In that case you will probably also have to use comma as the delimiter instead of space.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct quote(trim(id),"'")
  into :idlist separated by ',' 
  from ID
;
connect using database ;
create table want as
  select * from connection to database
(select w.* 
  from schema.tableimport w
  where w.indicator = 'Y'  and  w.type IN (2,3)
    and w.id IN (&amp;amp;idlist)
)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Jan 2023 22:23:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Pro-SQL-Import-merge-Quickly/m-p/855661#M42095</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-25T22:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: Pro SQL Import merge Quickly</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Pro-SQL-Import-merge-Quickly/m-p/855662#M42096</link>
      <description>Your question implies that the answer to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; question is yes, that one dataset is on a db and one is local. When you mix data between sources like this, SAS imports the full data and then filters. If you use the IN with the hardcoded values, the full query can be sent to the server and it's faster. So you can use &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s solution to have SAS 'hardcode' the values for you dynamically and it should work as fast.</description>
      <pubDate>Wed, 25 Jan 2023 22:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Pro-SQL-Import-merge-Quickly/m-p/855662#M42096</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-01-25T22:52:32Z</dc:date>
    </item>
  </channel>
</rss>

