<?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: How to embed proc sql within a data step? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-embed-proc-sql-within-a-data-step/m-p/341026#M77980</link>
    <description>&lt;P&gt;The data step looks more complicated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think a full proc sql is the simplest and readable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
&amp;nbsp;create table want as
&amp;nbsp;select * from have1
&amp;nbsp;where&amp;nbsp;var in (select distinct var in have2);
quit;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Mar 2017 01:37:53 GMT</pubDate>
    <dc:creator>afiqcjohari</dc:creator>
    <dc:date>2017-03-15T01:37:53Z</dc:date>
    <item>
      <title>How to embed proc sql within a data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-embed-proc-sql-within-a-data-step/m-p/341023#M77977</link>
      <description>&lt;PRE&gt;data want;
set have1;
where var in (
   proc sql; 
      select distinct var from have2;
  quit;);
 &lt;/PRE&gt;&lt;P&gt;Or how to write the proc sql part in pure data step?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 01:23:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-embed-proc-sql-within-a-data-step/m-p/341023#M77977</guid>
      <dc:creator>afiqcjohari</dc:creator>
      <dc:date>2017-03-15T01:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to embed proc sql within a data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-embed-proc-sql-within-a-data-step/m-p/341025#M77979</link>
      <description>&lt;P&gt;Your code would not work.&amp;nbsp; I think you want all the observations in HAVE1 with a value for VAR that also occurs in HAVE2:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set have1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if _n_=1 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hash h (dataset:'have2 (keep=var)');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definekey('var');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definedone();&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; rc=h.find();&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if rc=0;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or if you don't want implement hash objects, you can use a couple of proc sorts, followed by a merge:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have2 (keep=var) out=need2 nodupkey;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by var;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data=have1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by var;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; merge have1 have2 (in=in2);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by var;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if in2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The latter requires for more input/output.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 01:29:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-embed-proc-sql-within-a-data-step/m-p/341025#M77979</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-03-15T01:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to embed proc sql within a data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-embed-proc-sql-within-a-data-step/m-p/341026#M77980</link>
      <description>&lt;P&gt;The data step looks more complicated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think a full proc sql is the simplest and readable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
&amp;nbsp;create table want as
&amp;nbsp;select * from have1
&amp;nbsp;where&amp;nbsp;var in (select distinct var in have2);
quit;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 01:37:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-embed-proc-sql-within-a-data-step/m-p/341026#M77980</guid>
      <dc:creator>afiqcjohari</dc:creator>
      <dc:date>2017-03-15T01:37:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to embed proc sql within a data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-embed-proc-sql-within-a-data-step/m-p/341052#M77991</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/130031"&gt;@afiqcjohari&lt;/a&gt;, yes, SQL is simpler in this case, but you need the proper syntax:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
 create table want as
 select * from have1
 where var in (select var from have2);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Mar 2017 03:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-embed-proc-sql-within-a-data-step/m-p/341052#M77991</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-03-15T03:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to embed proc sql within a data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-embed-proc-sql-within-a-data-step/m-p/341111#M78021</link>
      <description>&lt;P&gt;Agree with other that stick to SQL for the whole query is the preferred&amp;nbsp;technique.&lt;/P&gt;
&lt;P&gt;But if there's another situation, and really would benefit from nesting SQL code, take a look at DS2.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 08:38:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-embed-proc-sql-within-a-data-step/m-p/341111#M78021</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-03-15T08:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to embed proc sql within a data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-embed-proc-sql-within-a-data-step/m-p/341117#M78023</link>
      <description>Thanks for this, it may come handy later. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 15 Mar 2017 09:17:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-embed-proc-sql-within-a-data-step/m-p/341117#M78023</guid>
      <dc:creator>afiqcjohari</dc:creator>
      <dc:date>2017-03-15T09:17:18Z</dc:date>
    </item>
  </channel>
</rss>

