<?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: WHERE clause operator requires compatible variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables/m-p/925624#M364247</link>
    <description>&lt;P&gt;What type (numeric or character) of variable is&amp;nbsp;weekcode in&amp;nbsp;ND_Preval?&amp;nbsp; Does it have a format attached? What format?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is numeric variable with a date type format (DATE, YYMMDD, etc) attached then your macro variables should have normal date values because of the use of MIN() and MAX() operators will remove the formatting.&amp;nbsp; So your code should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1    data test;
2      today=date();
3      format today date9.;
4    run;

NOTE: The data set WORK.TEST has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


5    proc sql noprint;
6    select min(today) into :today
7    from test;
8    quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


9    %put &amp;amp;=today;
TODAY=   23490&lt;/PRE&gt;
&lt;P&gt;But if it is character then the whole premise of your code can only work if the variable has strings like, 2024-04-24, that will sort in the same order as the date values that humans would see them as having.&amp;nbsp; Because when represented as string "01JUL2023" comes before "12SEP2000" because "0" comes before "1".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if the character variable does have strings in that YYYY-MM-DD (or YYYYMMDD) style then the macro variables will also and so your where condition will look something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;2023-01-01 le WeekCode le 2024-12-31&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which SAS will interpret as comparing the numbers 2021 and 1981 to a character string, &lt;STRONG&gt;hence the type mismatch.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Apr 2024 18:20:48 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-04-24T18:20:48Z</dc:date>
    <item>
      <title>WHERE clause operator requires compatible variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables/m-p/925613#M364244</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My code didn't work in Where statement.&amp;nbsp; Please help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
   select min(weekcode), max(weekcode) into :minweek, :maxweek
   from ND_Preval;
quit;
data MMWR_NREVSS_weekcode (keep= WeekCode );
	set lookup.MMWR;
	rename WEEK=WeekCode; *Renaming to match name in SAS program; 
run;
Proc sort data=MMWR_NREVSS_weekcode; by weekcode; run;

data ND_Preval_1;
	merge MMWR_NREVSS_weekcode ND_Preval (where=(&amp;amp;minweek. le WeekCode le &amp;amp;maxweek.));
	by weekcode;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;60   data ND_Preval_1;
61       merge MMWR_NREVSS_weekcode ND_Preval (where=(&amp;amp;minweek. le WeekCode le &amp;amp;maxweek.));
ERROR: WHERE clause operator requires compatible variables.
62       by weekcode;
63   run;
&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;</description>
      <pubDate>Wed, 24 Apr 2024 17:50:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables/m-p/925613#M364244</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2024-04-24T17:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE clause operator requires compatible variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables/m-p/925616#M364246</link>
      <description>&lt;P&gt;That means one of your Weekcode variables is character and the other numeric. Which one?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ideal solution would be to go back in your process, pick a variable type and be consistent.&lt;/P&gt;
&lt;P&gt;Or at use fix by converting numeric to character with a PUT or character to numeric with an Input. Your choice.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 17:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables/m-p/925616#M364246</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-04-24T17:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: WHERE clause operator requires compatible variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables/m-p/925624#M364247</link>
      <description>&lt;P&gt;What type (numeric or character) of variable is&amp;nbsp;weekcode in&amp;nbsp;ND_Preval?&amp;nbsp; Does it have a format attached? What format?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is numeric variable with a date type format (DATE, YYMMDD, etc) attached then your macro variables should have normal date values because of the use of MIN() and MAX() operators will remove the formatting.&amp;nbsp; So your code should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1    data test;
2      today=date();
3      format today date9.;
4    run;

NOTE: The data set WORK.TEST has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


5    proc sql noprint;
6    select min(today) into :today
7    from test;
8    quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


9    %put &amp;amp;=today;
TODAY=   23490&lt;/PRE&gt;
&lt;P&gt;But if it is character then the whole premise of your code can only work if the variable has strings like, 2024-04-24, that will sort in the same order as the date values that humans would see them as having.&amp;nbsp; Because when represented as string "01JUL2023" comes before "12SEP2000" because "0" comes before "1".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if the character variable does have strings in that YYYY-MM-DD (or YYYYMMDD) style then the macro variables will also and so your where condition will look something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;2023-01-01 le WeekCode le 2024-12-31&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which SAS will interpret as comparing the numbers 2021 and 1981 to a character string, &lt;STRONG&gt;hence the type mismatch.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 18:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-clause-operator-requires-compatible-variables/m-p/925624#M364247</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-24T18:20:48Z</dc:date>
    </item>
  </channel>
</rss>

