<?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 Subsetting dataset using WHERE and BETWEEN in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Subsetting-dataset-using-WHERE-and-BETWEEN/m-p/423975#M68149</link>
    <description>&lt;P&gt;I am&amp;nbsp;combine two data sets based on a patient's date of surgery falling between +/- 1 month of&amp;nbsp;when a patient completed their survey.&lt;/P&gt;&lt;P&gt;dataset abc has&amp;nbsp; variables lastname, firstname, dob, and survey_completed&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset xyz has variables last, first, date_birth, and date_surgery&lt;/P&gt;&lt;P&gt;Here's my code:&lt;/P&gt;&lt;P&gt;proc sql;&amp;nbsp;&lt;BR /&gt;create table&amp;nbsp;want as&lt;BR /&gt;select distinct t1.*,&lt;BR /&gt;intnx('month', t1.Survey_Completed, -1, 'sameday') as first_survey format=date9.,&lt;BR /&gt;intnx('month', t1.survey_completed, 1, 'sameday') as last_survey format=date9.,&lt;BR /&gt;t2.last,&lt;BR /&gt;t2.first,&lt;BR /&gt;t2.date_birth,&lt;BR /&gt;t2.date_surgery as DOS format date9.&lt;BR /&gt;from&amp;nbsp;abc as t1&lt;BR /&gt;left join xyz as t2&lt;BR /&gt;on t1.dob=t2.date_birth and t1.last_name=t2.last and t1.first_name=t2.first&lt;BR /&gt;where DOS between&amp;nbsp;first_survey and last_survey&lt;BR /&gt;order by last_name;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;with the above code I am getting the following error message:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ERROR: Expression using BETWEEN has components that are of different data types.&lt;BR /&gt;ERROR: The following columns were not found in the contributing tables: first_survey, last_survey.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;What am i doing wrong?&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Dec 2017 22:35:42 GMT</pubDate>
    <dc:creator>Mogamo_Khushua</dc:creator>
    <dc:date>2017-12-28T22:35:42Z</dc:date>
    <item>
      <title>Subsetting dataset using WHERE and BETWEEN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subsetting-dataset-using-WHERE-and-BETWEEN/m-p/423975#M68149</link>
      <description>&lt;P&gt;I am&amp;nbsp;combine two data sets based on a patient's date of surgery falling between +/- 1 month of&amp;nbsp;when a patient completed their survey.&lt;/P&gt;&lt;P&gt;dataset abc has&amp;nbsp; variables lastname, firstname, dob, and survey_completed&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset xyz has variables last, first, date_birth, and date_surgery&lt;/P&gt;&lt;P&gt;Here's my code:&lt;/P&gt;&lt;P&gt;proc sql;&amp;nbsp;&lt;BR /&gt;create table&amp;nbsp;want as&lt;BR /&gt;select distinct t1.*,&lt;BR /&gt;intnx('month', t1.Survey_Completed, -1, 'sameday') as first_survey format=date9.,&lt;BR /&gt;intnx('month', t1.survey_completed, 1, 'sameday') as last_survey format=date9.,&lt;BR /&gt;t2.last,&lt;BR /&gt;t2.first,&lt;BR /&gt;t2.date_birth,&lt;BR /&gt;t2.date_surgery as DOS format date9.&lt;BR /&gt;from&amp;nbsp;abc as t1&lt;BR /&gt;left join xyz as t2&lt;BR /&gt;on t1.dob=t2.date_birth and t1.last_name=t2.last and t1.first_name=t2.first&lt;BR /&gt;where DOS between&amp;nbsp;first_survey and last_survey&lt;BR /&gt;order by last_name;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;with the above code I am getting the following error message:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ERROR: Expression using BETWEEN has components that are of different data types.&lt;BR /&gt;ERROR: The following columns were not found in the contributing tables: first_survey, last_survey.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;What am i doing wrong?&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2017 22:35:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subsetting-dataset-using-WHERE-and-BETWEEN/m-p/423975#M68149</guid>
      <dc:creator>Mogamo_Khushua</dc:creator>
      <dc:date>2017-12-28T22:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting dataset using WHERE and BETWEEN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subsetting-dataset-using-WHERE-and-BETWEEN/m-p/423976#M68150</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;t2.date_surgery as DOS format date9. &amp;nbsp;&amp;lt;- missing the equal sign here&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What's the type/format on date_surgery before the query? I suspect it's a character variable and you'd need to convert it to a numeric variable and a SAS date first.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2017 22:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subsetting-dataset-using-WHERE-and-BETWEEN/m-p/423976#M68150</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-28T22:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting dataset using WHERE and BETWEEN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subsetting-dataset-using-WHERE-and-BETWEEN/m-p/423980#M68151</link>
      <description>&lt;P&gt;type is numeric and format is date9.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2017 22:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subsetting-dataset-using-WHERE-and-BETWEEN/m-p/423980#M68151</guid>
      <dc:creator>Mogamo_Khushua</dc:creator>
      <dc:date>2017-12-28T22:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting dataset using WHERE and BETWEEN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subsetting-dataset-using-WHERE-and-BETWEEN/m-p/423981#M68152</link>
      <description>&lt;P&gt;You must use the &lt;STRONG&gt;calculated&lt;/STRONG&gt; keyword when referring to a calculated column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where DOS between calculated first_survey and calculated last_survey&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Dec 2017 22:54:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subsetting-dataset-using-WHERE-and-BETWEEN/m-p/423981#M68152</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-12-28T22:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting dataset using WHERE and BETWEEN</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subsetting-dataset-using-WHERE-and-BETWEEN/m-p/423983#M68153</link>
      <description>&lt;P&gt;It works after using 'calculated'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2017 22:58:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subsetting-dataset-using-WHERE-and-BETWEEN/m-p/423983#M68153</guid>
      <dc:creator>Mogamo_Khushua</dc:creator>
      <dc:date>2017-12-28T22:58:07Z</dc:date>
    </item>
  </channel>
</rss>

