<?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: data step - subqueries like in proc sql? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/data-step-subqueries-like-in-proc-sql/m-p/578077#M163905</link>
    <description>&lt;P&gt;With data steps, you need to solve this in steps:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort
  data=HRCTRY_ECB_LIST (keep=HRCTRY_ECB)
  out=int1
;
by HRCTRY_ECB;
run;

proc sort
  data=wbit_book_raw_fx (
    keep=BOOK_COUNTERPARTYCOUNTRY BOOK_TXNREF SAS_Date WBIT_MNTLY
    rename=(BOOK_COUNTERPARTYCOUNTRY=HRCTRY_ECB)
    where=(SAS_Date = "&amp;amp;yesterday"d and WBIT_MNTLY=1)
  )
  out=int2 (drop=SAS_Date WBIT_MNTLY)
;
by HRCTRY_ECB;
run;

data int3;
merge
  int1 (in=i1)
  int2 (in=i2)
;
by HRCTRY_ECB;
if i1 and i2;
run;

proc sort data=int3 nodupkey;
by BOOK_TXNREF;
run;

proc sort data=wbit_book_raw_fx;
by BOOK_TXNREF;
run;

data BOOK_HRCTRY_&amp;amp;yesterday;
merge
  wbit_book_raw_fx (in=w1)
  int3 (in=i3 keep=BOOK_TXNREF)
;
by BOOK_TXNREF;
if w1 and i3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Although it looks like a lot of code, note that it took me less than three minutes to write it. Being used to write data step code does this for you. And most of the time was spent deciphering the SQL logic.&lt;/P&gt;
&lt;P&gt;Since I don't have data to test against, the code is untested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With memory-based means (hash objects), one could reduce the number of steps, but you would get code that is less easy to read and understand.&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jul 2019 13:41:15 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-07-31T13:41:15Z</dc:date>
    <item>
      <title>data step - subqueries like in proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-subqueries-like-in-proc-sql/m-p/578068#M163900</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what is the equivalent data-step statement for using subqueries to refer to columns of other list.&lt;/P&gt;&lt;P&gt;My SQL-Code:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; BOOK_HRCTRY_&amp;amp;yesterday &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select *&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; WORK.wbit_book_raw_fx&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; BOOK_TXNREF &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;in&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; BOOK_TXNREF&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; WORK.wbit_book_raw_fx&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; BOOK_COUNTERPARTYCOUNTRY &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;in&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; HRCTRY_ECB &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; HRCTRY_ECB_LIST) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;and&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;SAS_Date = &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;"&amp;amp;yesterday"d&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;and&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; WBIT_MNTLY=&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;order&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; BOOK_TXNREF;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;KS&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2019 13:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-subqueries-like-in-proc-sql/m-p/578068#M163900</guid>
      <dc:creator>fuhgidabowit</dc:creator>
      <dc:date>2019-07-31T13:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: data step - subqueries like in proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-subqueries-like-in-proc-sql/m-p/578072#M163902</link>
      <description>&lt;P&gt;When you do a MERGE in a data step, you can use the IN= option on any of the data sets being merged, and then only include records for which the proper in variable has a value of 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data abc;
    merge dataset1 dataset2 dataset3(in=in3);
    by id;
    if in3;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Jul 2019 13:29:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-subqueries-like-in-proc-sql/m-p/578072#M163902</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-31T13:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: data step - subqueries like in proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-subqueries-like-in-proc-sql/m-p/578077#M163905</link>
      <description>&lt;P&gt;With data steps, you need to solve this in steps:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort
  data=HRCTRY_ECB_LIST (keep=HRCTRY_ECB)
  out=int1
;
by HRCTRY_ECB;
run;

proc sort
  data=wbit_book_raw_fx (
    keep=BOOK_COUNTERPARTYCOUNTRY BOOK_TXNREF SAS_Date WBIT_MNTLY
    rename=(BOOK_COUNTERPARTYCOUNTRY=HRCTRY_ECB)
    where=(SAS_Date = "&amp;amp;yesterday"d and WBIT_MNTLY=1)
  )
  out=int2 (drop=SAS_Date WBIT_MNTLY)
;
by HRCTRY_ECB;
run;

data int3;
merge
  int1 (in=i1)
  int2 (in=i2)
;
by HRCTRY_ECB;
if i1 and i2;
run;

proc sort data=int3 nodupkey;
by BOOK_TXNREF;
run;

proc sort data=wbit_book_raw_fx;
by BOOK_TXNREF;
run;

data BOOK_HRCTRY_&amp;amp;yesterday;
merge
  wbit_book_raw_fx (in=w1)
  int3 (in=i3 keep=BOOK_TXNREF)
;
by BOOK_TXNREF;
if w1 and i3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Although it looks like a lot of code, note that it took me less than three minutes to write it. Being used to write data step code does this for you. And most of the time was spent deciphering the SQL logic.&lt;/P&gt;
&lt;P&gt;Since I don't have data to test against, the code is untested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With memory-based means (hash objects), one could reduce the number of steps, but you would get code that is less easy to read and understand.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2019 13:41:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-subqueries-like-in-proc-sql/m-p/578077#M163905</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-31T13:41:15Z</dc:date>
    </item>
  </channel>
</rss>

