<?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: Restricting to a range of dates in MM/DD/YYY format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Restricting-to-a-range-of-dates-in-MM-DD-YYY-format/m-p/859768#M339652</link>
    <description>&lt;P&gt;Your WHERE clause is comparing &lt;U&gt;numeric date variables&lt;/U&gt; (&lt;SPAN&gt;&lt;EM&gt;birth_infantdob&lt;/EM&gt; and&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;last_reg_dob&lt;/EM&gt;) with &lt;U&gt;strings&lt;/U&gt; ('01/01/2022' and '09/30/2022'). The dates you have hard-coded are, currently, just character strings. To make them SAS date values, use the DATE9. format (e.g., "01JAN2022"d).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	where ("01Jan2022"d &amp;lt;= birth_infantdob &amp;lt;= "30SEP2022"d
		or "01Jan2022"d &amp;lt;= reg_infantdob &amp;lt;= "30SEP2022"d);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Feb 2023 19:40:27 GMT</pubDate>
    <dc:creator>mklangley</dc:creator>
    <dc:date>2023-02-20T19:40:27Z</dc:date>
    <item>
      <title>Restricting to a range of dates in MM/DD/YYY format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restricting-to-a-range-of-dates-in-MM-DD-YYY-format/m-p/859765#M339650</link>
      <description>&lt;P&gt;This should be simple, but I can't get it to work &lt;span class="lia-unicode-emoji" title=":pouting_face:"&gt;😡&lt;/span&gt;&amp;nbsp; Here are the variable formats from proc contents:&lt;/P&gt;
&lt;P&gt;birth_infantdob Num 8 MMDDYY. &lt;BR /&gt;last_reg_dob Num 8 MMDDYY10. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried several variations of this approach, but I keep getting errors&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	where ('01/01/2022'&amp;lt;=birth_infantdob&amp;lt;='09/30/2022'
		or '01/01/2022'&amp;lt;=reg_infantdob&amp;lt;='09/30/2022');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This give me ERROR: WHERE clause operator requires compatible variables.&lt;/P&gt;
&lt;P&gt;I also tried removing the single quotes from around the dates, but then that says it's an "obvious false WHERE clause".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2023 19:16:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restricting-to-a-range-of-dates-in-MM-DD-YYY-format/m-p/859765#M339650</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2023-02-20T19:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: Restricting to a range of dates in MM/DD/YYY format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restricting-to-a-range-of-dates-in-MM-DD-YYY-format/m-p/859767#M339651</link>
      <description>&lt;P&gt;So from your PROC CONTENTS results you can see that the variables are NUMERIC.&amp;nbsp; So you cannot compare the values to strings like '01/01/2022'.&amp;nbsp; You need to compare them to DATE values.&amp;nbsp; You could type in the actual number that SAS uses to represent the first day of 2022, which is 22646.&amp;nbsp; But it will probably be a lot easier to type and easier to understand if you use a DATE literal instead.&amp;nbsp; DATE literals must use a string that the DATE informat can understand which is enclosed in quotes and has the letter D appended:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;1    data _null_;
2      x='01JAN2022'd ;
3      put x= ;
4    run;

x=22646
&lt;/PRE&gt;
&lt;P&gt;Remember that the format attached to a variable just determines how the value is DISPLAYED, not what it stored.&lt;/P&gt;
&lt;PRE&gt;5    data _null_;
6      x='02JAN2022'd ;
7      put x= / x= yymmdd10. / x= mmddyy10. / x= ddmmyy10. ;
8    run;

x=22647
x=2022-01-02
x=01/02/2022
x=02/01/2022
&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Feb 2023 19:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restricting-to-a-range-of-dates-in-MM-DD-YYY-format/m-p/859767#M339651</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-20T19:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: Restricting to a range of dates in MM/DD/YYY format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restricting-to-a-range-of-dates-in-MM-DD-YYY-format/m-p/859768#M339652</link>
      <description>&lt;P&gt;Your WHERE clause is comparing &lt;U&gt;numeric date variables&lt;/U&gt; (&lt;SPAN&gt;&lt;EM&gt;birth_infantdob&lt;/EM&gt; and&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;last_reg_dob&lt;/EM&gt;) with &lt;U&gt;strings&lt;/U&gt; ('01/01/2022' and '09/30/2022'). The dates you have hard-coded are, currently, just character strings. To make them SAS date values, use the DATE9. format (e.g., "01JAN2022"d).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	where ("01Jan2022"d &amp;lt;= birth_infantdob &amp;lt;= "30SEP2022"d
		or "01Jan2022"d &amp;lt;= reg_infantdob &amp;lt;= "30SEP2022"d);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2023 19:40:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restricting-to-a-range-of-dates-in-MM-DD-YYY-format/m-p/859768#M339652</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2023-02-20T19:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: Restricting to a range of dates in MM/DD/YYY format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restricting-to-a-range-of-dates-in-MM-DD-YYY-format/m-p/859769#M339653</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:Remember that the format attached to a variable just determines how the value is DISPLAYED, not what it stored.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Excellent point -- that is the source of my confusion!&amp;nbsp; The variables are displayed as 02/20/2022, but that is not how SAS is actually storing them.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2023 19:45:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restricting-to-a-range-of-dates-in-MM-DD-YYY-format/m-p/859769#M339653</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2023-02-20T19:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: Restricting to a range of dates in MM/DD/YYY format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restricting-to-a-range-of-dates-in-MM-DD-YYY-format/m-p/859770#M339654</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43822"&gt;@Wolverine&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:Remember that the format attached to a variable just determines how the value is DISPLAYED, not what it stored.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Excellent point -- that is the source of my confusion!&amp;nbsp; The variables are displayed as 02/20/2022, but that is not how SAS is actually storing them.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Right.&amp;nbsp; SAS uses the term as defined by meaning 6a in the &lt;A href="https://www.dictionary.com/browse/format" target="_self"&gt;dictionary.com definition&lt;/A&gt;.&amp;nbsp; Although SAS does use the term informat for the rules used for INPUT and reserves the term format for OUTPUT.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2023 19:56:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restricting-to-a-range-of-dates-in-MM-DD-YYY-format/m-p/859770#M339654</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-20T19:56:10Z</dc:date>
    </item>
  </channel>
</rss>

