<?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 Date format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/911160#M359295</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table with a date field whose values are in this form:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;14JUL2023:11:27:52.619374&lt;/P&gt;&lt;P&gt;10JAN2024:10:58:13.665456&lt;/P&gt;&lt;P&gt;20JAN2021:19:23:40.697598&lt;/P&gt;&lt;P&gt;28DEC2022:12:23:56.123211&lt;/P&gt;&lt;P&gt;18JAN2017:11:13:11.259936&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to know how to use this field in a SQL query, to select data from 2022 and 2023 for example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Wed, 10 Jan 2024 16:06:56 GMT</pubDate>
    <dc:creator>sasuser_8</dc:creator>
    <dc:date>2024-01-10T16:06:56Z</dc:date>
    <item>
      <title>Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/911160#M359295</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table with a date field whose values are in this form:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;14JUL2023:11:27:52.619374&lt;/P&gt;&lt;P&gt;10JAN2024:10:58:13.665456&lt;/P&gt;&lt;P&gt;20JAN2021:19:23:40.697598&lt;/P&gt;&lt;P&gt;28DEC2022:12:23:56.123211&lt;/P&gt;&lt;P&gt;18JAN2017:11:13:11.259936&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to know how to use this field in a SQL query, to select data from 2022 and 2023 for example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2024 16:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/911160#M359295</guid>
      <dc:creator>sasuser_8</dc:creator>
      <dc:date>2024-01-10T16:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/911161#M359296</link>
      <description>&lt;P&gt;First, a significant detail, that value is a datetime value, not a date. This is somewhat important to keep track of in SAS as Dates are numbers of days from 1 Jan 1960 and datetimes are numbers of seconds from midnight on that date. If you want to select date related intervals from datetime you would use the DATEPART function to extract the date from the datetime value for use in comparisons. You might further use other functions on that extracted date such as Year, Month others as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Comparing variable values to specific dates that you specify, called a date literal, you must provide the date information in the code as a quoted date9 (7 works but I detest 2 digit years for ambiguity) appearing value suffixed with the letter D to tell SAS you intend it to be used as a date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;example to select values in those years :&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table output as
   select *
   from yourdataset
   where year(datepart(datetimevariable)) between 2022 and 2023
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;or specific dates:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table output as
   select *
   from yourdataset
   where datepart(datetimevariable) between '15Jan2022'd and '23Feb2023'd
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;Since date values are numeric the typical comparisons for less than or greater than work but do want the date literal if the desired comparison value is not in a variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2024 16:19:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/911161#M359296</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-01-10T16:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/911172#M359303</link>
      <description>&lt;P&gt;Thank you !&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2024 17:02:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/911172#M359303</guid>
      <dc:creator>sasuser_8</dc:creator>
      <dc:date>2024-01-10T17:02:07Z</dc:date>
    </item>
  </channel>
</rss>

