<?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: How to pass literal date to where clause in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-literal-date-to-where-clause/m-p/928710#M365418</link>
    <description>&lt;P&gt;Assuming passing is a macro variable use the INPUT() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select * from temp where input("&amp;amp;macro_date", mmddyy10.) between col1 and col2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's a variable you're reading in via a join that is character then use input and the variable name.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select * from temp where input(variable_date, mmddyy10.) between col1 and col2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/428110"&gt;@current_thing&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I know I can reformat as '01Jan24'd and that works, but I want to literally pass 01/01/24 without having to reformat. Does that make sense?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 May 2024 17:29:17 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2024-05-16T17:29:17Z</dc:date>
    <item>
      <title>How to pass literal date to where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-literal-date-to-where-clause/m-p/928702#M365411</link>
      <description>&lt;P&gt;my query:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select * from temp where 01/01/24 between col1 and col2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;feel silly to ask but how can I pass the date that already is in date format? thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2024 17:00:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-literal-date-to-where-clause/m-p/928702#M365411</guid>
      <dc:creator>current_thing</dc:creator>
      <dc:date>2024-05-16T17:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass literal date to where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-literal-date-to-where-clause/m-p/928703#M365412</link>
      <description>&lt;P&gt;Date literals must be and can only be in this form: '01JAN2024'd (except you can use lower case letters)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select * from temp where '01JAN2024'd between col1 and col2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you said "&amp;nbsp;&lt;SPAN&gt;how can I pass the date that already is in date format", are you asking about a variable in a data set that is in date format? You didn't really say "variable" anywhere, but if that's what you mean, and let's assume the variable name is DATE and it contains true SAS date value (does it?) then you can use&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select * from temp where DATE between col1 and col2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;but there are a lot of assumptions needed to make that work. If it is not working, then explain in a lot more detail, and provide not only the PROC CONTENTS of your data set, but also typical values of DATE and COL1 and COL2.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2024 17:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-literal-date-to-where-clause/m-p/928703#M365412</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-05-16T17:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass literal date to where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-literal-date-to-where-clause/m-p/928705#M365414</link>
      <description>&lt;P&gt;I know I can reformat as '01Jan24'd and that works, but I want to literally pass 01/01/24 without having to reformat. Does that make sense?&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2024 17:13:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-literal-date-to-where-clause/m-p/928705#M365414</guid>
      <dc:creator>current_thing</dc:creator>
      <dc:date>2024-05-16T17:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass literal date to where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-literal-date-to-where-clause/m-p/928706#M365415</link>
      <description>&lt;P&gt;To answer directly your question about can it be 01/01/24, the answer is NO&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We need a much more detailed explanation. Include in your explanation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Give background of this problem. Background means explanation, it should not address any SAS code issues.&lt;/LI&gt;
&lt;LI&gt;Why does it have to be 01/01/24 looking just like that? What is wrong with some other appearance such as '01JAN2024'd?&lt;/LI&gt;
&lt;LI&gt;What are typical values of COL1? Is col1 numeric or character?&lt;/LI&gt;
&lt;LI&gt;What are typical values of COL2? Is col2 numeric or character?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please address all of these points, and not just one.&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2024 17:22:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-literal-date-to-where-clause/m-p/928706#M365415</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-05-16T17:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass literal date to where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-literal-date-to-where-clause/m-p/928709#M365417</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/428110"&gt;@current_thing&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I know I can reformat as '01Jan24'd and that works, but I want to literally pass 01/01/24 without having to reformat. Does that make sense?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not in SAS terms for SAS date values unless&amp;nbsp; you are willing to put '01/01/24' as the argument of an INPUT function call such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
select * from temp where input('01/01/24',mmddyy10.) between col1 and col2;
quit;&lt;/PRE&gt;
&lt;P&gt;or the DDMMYY10 informat, or whatever is needed to parse the string 01/01/24 which could be 1 Jan 2024 (or 1 Jan 1924 really should use 4-digit years for clarity) or 24 Jan 2001 (or 24 Jan 1901 or ... as I said use 4-digit years)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The INPUT function would expect character value in quotes. Without quotes your value will be treated as a numeric value of about 0.0416666667&amp;nbsp; (1 divided by 1 divided by 24) which is very unlikely to appear between date values unless Col1 is&amp;nbsp; 1 Jan 1960 (0 in numeric terms) or earlier (negative numbers).&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2024 17:23:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-literal-date-to-where-clause/m-p/928709#M365417</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-16T17:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass literal date to where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-literal-date-to-where-clause/m-p/928710#M365418</link>
      <description>&lt;P&gt;Assuming passing is a macro variable use the INPUT() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select * from temp where input("&amp;amp;macro_date", mmddyy10.) between col1 and col2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's a variable you're reading in via a join that is character then use input and the variable name.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select * from temp where input(variable_date, mmddyy10.) between col1 and col2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/428110"&gt;@current_thing&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I know I can reformat as '01Jan24'd and that works, but I want to literally pass 01/01/24 without having to reformat. Does that make sense?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2024 17:29:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-literal-date-to-where-clause/m-p/928710#M365418</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-05-16T17:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass literal date to where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-literal-date-to-where-clause/m-p/928711#M365419</link>
      <description>&lt;P&gt;Your query is comparing a date value -- which is essentially a number -- to a range defined by two other values. Since your example value (01/01/2024) is just a series of characters that SQL won't resolve as a date, you have to take a step to convert it to a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe that value is coming to you from somewhere else and that's why you don't want to use the '01Jan2024'd date literal format. Instead you could convert it "inline" with a function that will yield a number:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%sysfunc(inputn(01/01/2024,mmddyy10))&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 May 2024 17:31:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-literal-date-to-where-clause/m-p/928711#M365419</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2024-05-16T17:31:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass literal date to where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-literal-date-to-where-clause/m-p/928714#M365422</link>
      <description>&lt;P&gt;that's it! thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2024 17:34:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-literal-date-to-where-clause/m-p/928714#M365422</guid>
      <dc:creator>current_thing</dc:creator>
      <dc:date>2024-05-16T17:34:20Z</dc:date>
    </item>
  </channel>
</rss>

