<?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: SAS QUERY in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/SAS-QUERY/m-p/242884#M55871</link>
    <description>&lt;P&gt;Either way, you would need to consider the case that observations from X would be selected multiple times by PROC SQL if there were two or more "matching" Y records. For example, if Y contained a third observation with ID='140011001' and date='2011-09-10', the current result dataset would double from 6 to 12 observations. Of course, this could be avoided by selecting &lt;FONT face="courier new,courier"&gt;DISTINCT&lt;/FONT&gt; ... including an additional variable, e.g. a record number, which uniquely identifies observations in X.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Also, please note that with your character dates, the BETWEEN condition would read&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;input(x.date,yymmdd10.) between input(y.date,yymmdd10.)-3 and input(y.date,yymmdd10.)+3&lt;/FONT&gt;.&lt;/P&gt;</description>
    <pubDate>Tue, 12 Jan 2016 10:15:17 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2016-01-12T10:15:17Z</dc:date>
    <item>
      <title>SAS QUERY</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-QUERY/m-p/242800#M55856</link>
      <description>&lt;P&gt;Hi Friends,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone help me with below query. I have two datasets X and Y.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;X has two variables ID and date&lt;/P&gt;
&lt;P&gt;Y has two variables ID and date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID is the key variable and can have different number of records in X and Y for the same ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For every ID and DATE in X, Date should be compared &amp;nbsp;with Y and should output only those where X.DATE=+_3 days.Y.date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I Hope i explained and thanks in advance.&lt;/P&gt;
&lt;P&gt;Sample data&lt;/P&gt;
&lt;P&gt;x:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;140011001 2011-09-09&amp;nbsp;&lt;BR /&gt;140011001 2011-09-11&amp;nbsp;&lt;BR /&gt;140011001 2011-09-11&amp;nbsp;&lt;BR /&gt;140011001 2011-09-11&amp;nbsp;&lt;BR /&gt;140011001 2011-09-11&amp;nbsp;&lt;BR /&gt;140011001 2011-09-11&amp;nbsp;&lt;BR /&gt;140011001 2011-09-20&amp;nbsp;&lt;BR /&gt;140011001 2011-09-20&amp;nbsp;&lt;BR /&gt;140011001 2011-09-20&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Y:&lt;/P&gt;
&lt;P&gt;140011001 2011-09-09&lt;BR /&gt;140011001 2011-09-29&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OUTPUT:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;140011001 2011-09-20&amp;nbsp;&lt;BR /&gt; 140011001 2011-09-20&amp;nbsp;&lt;BR /&gt; 140011001 2011-09-20&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2016 20:17:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-QUERY/m-p/242800#M55856</guid>
      <dc:creator>rakeshvvv</dc:creator>
      <dc:date>2016-01-11T20:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS QUERY</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-QUERY/m-p/242802#M55857</link>
      <description>&lt;P&gt;It doesn't look like your data matches your rule,&amp;nbsp;2011-09-20 +-3 days is 2011-09-17 and 2011-09-23 and those dates aren't in the second table. Please clarify your requirements.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2016 20:23:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-QUERY/m-p/242802#M55857</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-11T20:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS QUERY</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-QUERY/m-p/242804#M55858</link>
      <description>&lt;P&gt;Are your date variables SAS Date value or character? The comparisons will work much better with SAS data values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also your requirement seems to say that the X date is 3 days from the Y date but your example out put shows the X date 2011-09-20&amp;nbsp;to be 9 days from the displayed Y date of 2011-09-20. You may need to expand on the detales of the rule for us.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2016 20:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-QUERY/m-p/242804#M55858</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-01-11T20:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: SAS QUERY</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-QUERY/m-p/242806#M55859</link>
      <description>&lt;P&gt;The data is correct.....date is a character variable in yyyymmdd format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;140011001 2011-09-09&amp;nbsp;&lt;BR /&gt; 140011001 2011-09-11&amp;nbsp;&lt;BR /&gt; 140011001 2011-09-11&amp;nbsp;&lt;BR /&gt; 140011001 2011-09-11&amp;nbsp;&lt;BR /&gt; 140011001 2011-09-11&amp;nbsp;&lt;BR /&gt; 140011001 2011-09-11&amp;nbsp;&lt;BR /&gt; 140011001 2011-09-20&amp;nbsp;&lt;BR /&gt; 140011001 2011-09-20&amp;nbsp;&lt;BR /&gt; 140011001 2011-09-20&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Y:&lt;/P&gt;
&lt;P&gt;140011001 2011-09-09&lt;BR /&gt; 140011001 2011-09-29&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OUTPUT:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;140011001 2011-09-09&amp;nbsp;&lt;BR /&gt; 140011001 2011-09-11&amp;nbsp;&lt;BR /&gt; 140011001 2011-09-11&amp;nbsp;&lt;BR /&gt; 140011001 2011-09-11&amp;nbsp;&lt;BR /&gt; 140011001 2011-09-11&amp;nbsp;&lt;BR /&gt; 140011001 2011-09-11&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Reason for output: As the first 6 records in X(2011-09-09&amp;nbsp; 2011-09-11&amp;nbsp;) within 3 days of Y(2011-09-09). We should output those records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;140011001 2011-09-20= it is beyond 3 days from Y and hence we are not outputting those records&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2016 20:37:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-QUERY/m-p/242806#M55859</guid>
      <dc:creator>rakeshvvv</dc:creator>
      <dc:date>2016-01-11T20:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: SAS QUERY</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-QUERY/m-p/242848#M55868</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
input id : $20. date yymmdd12.;
format date yymmdd.;
cards;
140011001 2011-09-09 
140011001 2011-09-11 
140011001 2011-09-11 
140011001 2011-09-11 
140011001 2011-09-11 
140011001 2011-09-11 
140011001 2011-09-20 
140011001 2011-09-20 
140011001 2011-09-20 
;
run;
data y;
input id : $20. date yymmdd12.;
format date yymmdd.;
cards;
140011001 2011-09-09
140011001 2011-09-29
;
run;
proc sql;
create table want as
 select x.*
  from x,y
   where x.id eq y.id and x.date between y.date-3 and y.date+3;
quit;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Jan 2016 02:33:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-QUERY/m-p/242848#M55868</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-01-12T02:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS QUERY</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-QUERY/m-p/242870#M55870</link>
      <description>&lt;P&gt;Wouldn't it be better let the join take care of merging the two tables, and let the where-statement take care of the proper selection?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&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;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;create&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;table&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; want &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;x.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;*&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; x &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; a&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;left&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;join&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; y &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; b &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;on&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; (a.id = b.id)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;where&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; abs(a.date - b.date) &amp;lt;= &lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;3&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Personally I prefer using abs(x-y)&amp;lt;=3 -&amp;nbsp;makes it&amp;nbsp;more explicit where the boundaries of the selection are...&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jan 2016 08:00:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-QUERY/m-p/242870#M55870</guid>
      <dc:creator>JohndeKroon</dc:creator>
      <dc:date>2016-01-12T08:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS QUERY</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-QUERY/m-p/242884#M55871</link>
      <description>&lt;P&gt;Either way, you would need to consider the case that observations from X would be selected multiple times by PROC SQL if there were two or more "matching" Y records. For example, if Y contained a third observation with ID='140011001' and date='2011-09-10', the current result dataset would double from 6 to 12 observations. Of course, this could be avoided by selecting &lt;FONT face="courier new,courier"&gt;DISTINCT&lt;/FONT&gt; ... including an additional variable, e.g. a record number, which uniquely identifies observations in X.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Also, please note that with your character dates, the BETWEEN condition would read&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;input(x.date,yymmdd10.) between input(y.date,yymmdd10.)-3 and input(y.date,yymmdd10.)+3&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jan 2016 10:15:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-QUERY/m-p/242884#M55871</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-12T10:15:17Z</dc:date>
    </item>
  </channel>
</rss>

