<?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 Using a Date Constant with a IN Operator in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Date-Constant-with-a-IN-Operator/m-p/330647#M74219</link>
    <description>&lt;P&gt;I am trying to use date constants in a numeric range.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&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 t;

	input date;
	format date ddmmyy10.;
datalines;
0
1
2
3
4
5
6
7
;
run;

proc print data=work.t;

	*where date in (3:6);
	where date in ('04JAN1960'd : '07JAN1960'd);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first where clause uses the numeric date and the programs execute without errors.&lt;/P&gt;
&lt;P&gt;The second where clause uses the date constant&amp;nbsp;and will generate an error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The documentation specifies that the N and M should be numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is why would it fail with a date constant or even a variable that is numeric when using the range feature with the IN operator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p00iah2thp63bmn1lt20esag14lh.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p00iah2thp63bmn1lt20esag14lh.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;M, N, and all the integers&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Feb 2017 22:50:48 GMT</pubDate>
    <dc:creator>arnouxvr</dc:creator>
    <dc:date>2017-02-07T22:50:48Z</dc:date>
    <item>
      <title>Using a Date Constant with a IN Operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Date-Constant-with-a-IN-Operator/m-p/330647#M74219</link>
      <description>&lt;P&gt;I am trying to use date constants in a numeric range.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&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 t;

	input date;
	format date ddmmyy10.;
datalines;
0
1
2
3
4
5
6
7
;
run;

proc print data=work.t;

	*where date in (3:6);
	where date in ('04JAN1960'd : '07JAN1960'd);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first where clause uses the numeric date and the programs execute without errors.&lt;/P&gt;
&lt;P&gt;The second where clause uses the date constant&amp;nbsp;and will generate an error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The documentation specifies that the N and M should be numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is why would it fail with a date constant or even a variable that is numeric when using the range feature with the IN operator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p00iah2thp63bmn1lt20esag14lh.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p00iah2thp63bmn1lt20esag14lh.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;M, N, and all the integers&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 22:50:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Date-Constant-with-a-IN-Operator/m-p/330647#M74219</guid>
      <dc:creator>arnouxvr</dc:creator>
      <dc:date>2017-02-07T22:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Date Constant with a IN Operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Date-Constant-with-a-IN-Operator/m-p/330652#M74222</link>
      <description>&lt;P&gt;I would assume that the rules for parsing the command doesn't support handling conversion of date literals. &amp;nbsp;It would also probably fail if you tried to use hexadecimal or binary literals also.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use macro functions to convert your human readable date into an integer that the SAS compiler will understand. &amp;nbsp;Try wrapping the date literals inside of the %SYSEVALF() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;20   data x;
21    set sashelp.class ;
22    where age in (10:%sysevalf('01JAN2017'd));
23   run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
      WHERE (age=INT(age)) and (age&amp;gt;=10 and age&amp;lt;=20820);
NOTE: The data set WORK.X has 19 observations and 5 variables.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Feb 2017 22:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Date-Constant-with-a-IN-Operator/m-p/330652#M74222</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-02-07T22:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Date Constant with a IN Operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-Date-Constant-with-a-IN-Operator/m-p/330656#M74224</link>
      <description>&lt;P&gt;Thank you, Tom.&lt;BR /&gt;&lt;BR /&gt;The solution works. I just wonder why it would fail when using a date&lt;BR /&gt;constant or numeric variable.&lt;BR /&gt;&lt;BR /&gt;Explanation on SAS inner workings with &lt;SPAN&gt;%sysevalf&lt;/SPAN&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using the macro function the macro processor will first run and execute the macro code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro processor will convert the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if curr_date in (%sysevalf('01FEB2017'd) : %sysevalf('28FEB2017'd)) then do;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if curr_date in (20851 : 20878) then do;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and then the compiler can run the code as if it was numeric.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 01:14:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-Date-Constant-with-a-IN-Operator/m-p/330656#M74224</guid>
      <dc:creator>arnouxvr</dc:creator>
      <dc:date>2017-02-08T01:14:46Z</dc:date>
    </item>
  </channel>
</rss>

