<?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: Using subqueries in SAS DI in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Using-subqueries-in-SAS-DI/m-p/429635#M13295</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just to provide a feedback.&amp;nbsp;Although&amp;nbsp; JOIN can help in some cases, it is not appropriate in some other.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using &lt;STRONG&gt;Lookup&lt;/STRONG&gt; transformation is the nice way to handle this, both for IN and NOT IN options.&lt;/P&gt;&lt;P&gt;WIth clever playing with error handling, it is possible to get&amp;nbsp;rows from main table&amp;nbsp;that contain values from control table in result table and the ones which do not contain it in the&amp;nbsp;exception table, for example.&lt;BR /&gt;&lt;BR /&gt;Handy and clean.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="lookup_01.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18022iC61F00D13424B5A0/image-size/large?v=v2&amp;amp;px=999" role="button" title="lookup_01.png" alt="lookup_01.png" /&gt;&lt;/span&gt;&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-left" image-alt="lookup_02.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18023i1F8A05EAAEB924A5/image-size/large?v=v2&amp;amp;px=999" role="button" title="lookup_02.png" alt="lookup_02.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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-left" image-alt="lookup_03.png" style="width: 511px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18024i70CC728E8D053177/image-size/large?v=v2&amp;amp;px=999" role="button" title="lookup_03.png" alt="lookup_03.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Jan 2018 15:06:29 GMT</pubDate>
    <dc:creator>strsljen</dc:creator>
    <dc:date>2018-01-22T15:06:29Z</dc:date>
    <item>
      <title>Using subqueries in SAS DI</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Using-subqueries-in-SAS-DI/m-p/428360#M13206</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to use support tables within SAS DI job within WHERE CLAUSE but I am getting syntax error near (SELECT under IN part:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create view work.W20YF54Y as
      select
         PERIODE_MONTH_KEY,
         MAIN_NUMBER,
         DRM_TRAFFIC_CATEGORY,
         SUM_of_TRAFFIC_NUMBER_EVENTS,
         SUM_of_TRAFFIC_NET_AMOUNT,
         SUM_of_TRAFFIC_NET_DISCOUNT_AMOU,
         TRAFFIC_TOTAL_AMOUNT,
         SUM_of_TRAFFIC_VOLUME_TOTAL,
         SUM_of_TRAFFIC_DURATION,
         TRAFFIC_LOCATION_ID,
         TRAFFIC_LOCATION_DESC,
         current_country_grouping_roam,
         current_country_grouping_dest,
         SUBSCRIPTION_KEY,
         SUBSCR_USER_KEY,
         SUBSCR_OWNER_KEY,
         TWIN_DESC,
         Ant_minutter
   from &amp;amp;SYSLAST
      where SOURCE_SYSTEM_KEY_3 IN (
                   SELECT SVALUE
                      FROM CONF_ARPU_01 
                      WHERE SNAME='SOURCE_SYSTEM_KEY_3' 
         )
   ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can someone advise me around this part:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;     where SOURCE_SYSTEM_KEY_3 IN (
                   SELECT SVALUE
                      FROM CONF_ARPU_01 
                      WHERE SNAME='SOURCE_SYSTEM_KEY_3' 
         )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Error message:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OTE: Libref ARPU01 was successfully assigned as follows: 
      Engine:        BASE 
      Physical Name: /sasdata/Business/Prod/DI/t915925
3          data null;
4             set arpu01.W1LNYK37;
5             where SOURCE_SYSTEM_KEY_3 IN (
6                       SELECT SVALUE
                        ______
                        22
                        202
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant, 
              a missing value, -.  

ERROR 202-322: The option or parameter is not recognized and will be ignored.

7                          FROM CONF_ARPU_01
8                          WHERE SNAME='SOURCE_SYSTEM_KEY_3'
9             );
ERROR: Syntax error while parsing WHERE clause.
10         run cancel;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I use subqueries in SAS DI?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 13:48:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Using-subqueries-in-SAS-DI/m-p/428360#M13206</guid>
      <dc:creator>strsljen</dc:creator>
      <dc:date>2018-01-17T13:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using subqueries in SAS DI</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Using-subqueries-in-SAS-DI/m-p/428366#M13207</link>
      <description>&lt;P&gt;The log does ont match the code you provide (or the macro variable used resolves to code unexpectedly:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; null&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token number"&gt;4&lt;/SPAN&gt;             &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; arpu01&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;W1LNYK37&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token number"&gt;5&lt;/SPAN&gt;             &lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; SOURCE_SYSTEM_KEY_3 &lt;SPAN class="token operator"&gt;IN&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;
&lt;SPAN class="token number"&gt;6&lt;/SPAN&gt;                       &lt;SPAN class="token statement"&gt;SELECT&lt;/SPAN&gt; SVALUE&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will note the data _null_; set arpu01.w1lnyk37; before the where statement, this is what is wrong - you cannot have datastep code in an SQL statement. Why are you (and what does this resolve to) using&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;SYSLAST&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&amp;nbsp; Its likely that is pointing to the last dataset used, which could likely be a data _null_.&amp;nbsp; Specify the table you want to select from and drop this macro variable.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 14:05:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Using-subqueries-in-SAS-DI/m-p/428366#M13207</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-17T14:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using subqueries in SAS DI</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Using-subqueries-in-SAS-DI/m-p/428430#M13210</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;points out, it's syntactically wrong.&lt;/P&gt;
&lt;P&gt;But in DIS you should always try to strive for using standard transformations, not user written code.&lt;/P&gt;
&lt;P&gt;When doing so, it's less likely to get this wrong. The SQL Join transformation has support for sub-queries for instance.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 15:38:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Using-subqueries-in-SAS-DI/m-p/428430#M13210</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-01-17T15:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using subqueries in SAS DI</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Using-subqueries-in-SAS-DI/m-p/428725#M13222</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the valuable inputs. I managed to set an example by using user written code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create view work.W2CVVADN as
      select
         PERIODE_MONTH_KEY,
         MAIN_NUMBER,
         DRM_TRAFFIC_CATEGORY,
         SUM_of_TRAFFIC_NUMBER_EVENTS,
         SUM_of_TRAFFIC_NET_AMOUNT,
         SUM_of_TRAFFIC_NET_DISCOUNT_AMOU,
         TRAFFIC_TOTAL_AMOUNT,
         SUM_of_TRAFFIC_VOLUME_TOTAL,
         SUM_of_TRAFFIC_DURATION,
         TRAFFIC_LOCATION_ID,
         TRAFFIC_LOCATION_DESC,
         current_country_grouping_roam,
         current_country_grouping_dest,
         SUBSCRIPTION_KEY,
         SUBSCR_USER_KEY,
         SUBSCR_OWNER_KEY,
         TWIN_DESC,
         SOURCE_SYSTEM_KEY_3,
         Ant_minutter
   from &amp;amp;SYSLAST
    WHERE SOURCE_SYSTEM_KEY_3 IN (
		SELECT SVALUE
			FROM BUSDM.CONF_ARPU_01 
         WHERE SNAME='SOURCE_SYSTEM_KEY_3' 
	)
   ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I also had to add library assigning in precode for that extract job.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME BUSDM ORACLE&amp;nbsp; PATH=XXX&amp;nbsp; SCHEMA=XXX&amp;nbsp; USER=XXX&amp;nbsp; PASSWORD="{SAS004}XXX" ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I can use it that way, but I also don't like the idea of using User written code unless I have no other choce.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I checked this &lt;A href="http://support.sas.com/documentation/cdl/en/etlug/67323/HTML/default/viewer.htm#p0tpbt07h7iy7qn1071lwlx2u2sh.htm" target="_self"&gt;document&lt;/A&gt;, but I have a problem following its logic.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;If someone can write simplest possible example for it when I have 1 source table and need to esssentially run this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SELECT * FROM TABLE1
  WHERE SOURCE_SYSTEM_KEY_3 IN (
        SELECT SVALUE FROM CONFTABLE
          WHERE SNAME='SOURCE_SYSTEM_KEY_3' 
   )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;that would be more than helpful.&lt;/P&gt;&lt;P&gt;Both tables are members of the existing SAS libraries.&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2018 09:20:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Using-subqueries-in-SAS-DI/m-p/428725#M13222</guid>
      <dc:creator>strsljen</dc:creator>
      <dc:date>2018-01-18T09:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using subqueries in SAS DI</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Using-subqueries-in-SAS-DI/m-p/428727#M13223</link>
      <description>&lt;P&gt;In the simplest possible way this:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;   &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;SYSLAST
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is incorrect.&amp;nbsp; As you can see in the example you gave:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;FROM&lt;/SPAN&gt; TABLE1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Where it is specifying a specific table - if you specify a specific table, then your code will work. Table1 in that case is the datatable, just replace &amp;amp;SYSLAST with the datatable you want to work on.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2018 09:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Using-subqueries-in-SAS-DI/m-p/428727#M13223</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-18T09:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using subqueries in SAS DI</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Using-subqueries-in-SAS-DI/m-p/428738#M13225</link>
      <description>&lt;P&gt;First, do not &lt;STRONG&gt;EVER&lt;/STRONG&gt; have a libanme statement in the pre-code. It should be defined as a Library object.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, I don't think you'r query need to be a sub query, I imagine you will get the same result by doing an inner join, and again, use the SQL Join transformation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;: actually, it is best practice to use &amp;amp;SYSLAST as much as possible in DI Studio development. This is because you want as much of the code to be metadata driven. So &amp;amp;SYSLAST and other helper macro variables will be set automatically by the metadata code generation engine. BY hard-coding tables names in the code will make the maintenance much harder.&lt;/P&gt;
&lt;P&gt;In this particular example, if you use standard transformations as SQL Join, the code (including FROM &amp;amp;SYSLAST) is generated by DI Studio, not the developer.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2018 10:50:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Using-subqueries-in-SAS-DI/m-p/428738#M13225</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-01-18T10:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using subqueries in SAS DI</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Using-subqueries-in-SAS-DI/m-p/428744#M13228</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;&amp;nbsp;thanks for eye opener - yes, I can use JOIN to acomplish the same thing. Well, this was interesting. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will continue with JOIN instead.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2018 11:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Using-subqueries-in-SAS-DI/m-p/428744#M13228</guid>
      <dc:creator>strsljen</dc:creator>
      <dc:date>2018-01-18T11:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using subqueries in SAS DI</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Using-subqueries-in-SAS-DI/m-p/429635#M13295</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just to provide a feedback.&amp;nbsp;Although&amp;nbsp; JOIN can help in some cases, it is not appropriate in some other.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using &lt;STRONG&gt;Lookup&lt;/STRONG&gt; transformation is the nice way to handle this, both for IN and NOT IN options.&lt;/P&gt;&lt;P&gt;WIth clever playing with error handling, it is possible to get&amp;nbsp;rows from main table&amp;nbsp;that contain values from control table in result table and the ones which do not contain it in the&amp;nbsp;exception table, for example.&lt;BR /&gt;&lt;BR /&gt;Handy and clean.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="lookup_01.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18022iC61F00D13424B5A0/image-size/large?v=v2&amp;amp;px=999" role="button" title="lookup_01.png" alt="lookup_01.png" /&gt;&lt;/span&gt;&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-left" image-alt="lookup_02.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18023i1F8A05EAAEB924A5/image-size/large?v=v2&amp;amp;px=999" role="button" title="lookup_02.png" alt="lookup_02.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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-left" image-alt="lookup_03.png" style="width: 511px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18024i70CC728E8D053177/image-size/large?v=v2&amp;amp;px=999" role="button" title="lookup_03.png" alt="lookup_03.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2018 15:06:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Using-subqueries-in-SAS-DI/m-p/429635#M13295</guid>
      <dc:creator>strsljen</dc:creator>
      <dc:date>2018-01-22T15:06:29Z</dc:date>
    </item>
  </channel>
</rss>

