<?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 do I write this proc sql statement using SAS datastep ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-this-proc-sql-statement-using-SAS-datastep/m-p/299524#M63193</link>
    <description>&lt;P&gt;I guess that this is one of the cases where SQl can do things that the data step can't, since we could do the merge on id alone, but a subsequent subsetting if with the further conditions would prevent the output of an "a" record if there were only matching "b" IDs that don't fulfil the additional conditions.&lt;/P&gt;</description>
    <pubDate>Tue, 20 Sep 2016 12:34:53 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-09-20T12:34:53Z</dc:date>
    <item>
      <title>How do I write this proc sql statement using SAS datastep ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-this-proc-sql-statement-using-SAS-datastep/m-p/299517#M63189</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;create table test&amp;nbsp;as&lt;BR /&gt;select a.*, b.one&lt;BR /&gt;from dat1&amp;nbsp;as a left join&lt;BR /&gt;dat2&amp;nbsp;as b&lt;BR /&gt;on a.id eq b.id and ((a.date1&amp;nbsp;eq b.date1) or (b.date1&amp;nbsp;&amp;lt;= a.date1 &amp;lt;= b.date2))&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;How do I write this using merge statement ?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was able to write the below, but how do I add the condition&amp;nbsp;&lt;SPAN&gt;(b.&lt;/SPAN&gt;&lt;SPAN&gt;date1&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;lt;= a.&lt;/SPAN&gt;&lt;SPAN&gt;date1&lt;/SPAN&gt;&lt;SPAN&gt; &amp;lt;= b.&lt;/SPAN&gt;&lt;SPAN&gt;date2&lt;/SPAN&gt;&lt;SPAN&gt;)) ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;merge dat1(in=a) dat2(in=b);&lt;BR /&gt;by id date1;&lt;BR /&gt;if a;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2016 11:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-this-proc-sql-statement-using-SAS-datastep/m-p/299517#M63189</guid>
      <dc:creator>bobbyc</dc:creator>
      <dc:date>2016-09-20T11:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write this proc sql statement using SAS datastep ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-this-proc-sql-statement-using-SAS-datastep/m-p/299519#M63191</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
merge dat1(in=a) dat2(in=b rename=(date1=b_date1 date2=b_date2));
by id ;
if a and &lt;SPAN&gt;b_&lt;/SPAN&gt;&lt;SPAN&gt;date1&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;lt;= &lt;/SPAN&gt;&lt;SPAN&gt;date1&lt;/SPAN&gt;&lt;SPAN&gt; &amp;lt;= b_&lt;/SPAN&gt;&lt;SPAN&gt;date2&lt;/SPAN&gt;;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2016 12:04:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-this-proc-sql-statement-using-SAS-datastep/m-p/299519#M63191</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2016-09-20T12:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write this proc sql statement using SAS datastep ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-this-proc-sql-statement-using-SAS-datastep/m-p/299524#M63193</link>
      <description>&lt;P&gt;I guess that this is one of the cases where SQl can do things that the data step can't, since we could do the merge on id alone, but a subsequent subsetting if with the further conditions would prevent the output of an "a" record if there were only matching "b" IDs that don't fulfil the additional conditions.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2016 12:34:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-write-this-proc-sql-statement-using-SAS-datastep/m-p/299524#M63193</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-20T12:34:53Z</dc:date>
    </item>
  </channel>
</rss>

