<?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: Date part in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-part/m-p/875492#M345916</link>
    <description>&lt;P&gt;If the value is a SAS datetime value then "substr" would ask SAS to convert the underlying datetime value (which is typically a moderately large number of seconds) to character so that SUBSTR can be applied as shown in this log:&lt;/P&gt;
&lt;PRE&gt;1    data example;
2       x="01MAR2022:00:00:00"dt;
3       y=substr(x,1,9);
4    run;

NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
      3:13
&lt;/PRE&gt;
&lt;P&gt;Which has a result of 1961712, which are the first 9 characters of the value 1961712000 which is the number of seconds since midnight 01JAN1960 (or 01Jan1960:00:00:00).&lt;/P&gt;
&lt;P&gt;It appears that your value is a DATETIME value (type is numeric and the current format assigned to the variable is DATETIME19. (or longer).&lt;/P&gt;
&lt;P&gt;You want the DATEPART function to extract the value &lt;STRONG&gt;AND&lt;/STRONG&gt; to show the value as a date assign a&amp;nbsp;&lt;STRONG&gt;different&lt;/STRONG&gt; format such as DATE9&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   x="01MAR2022:00:00:00"dt;
   put x= datetime18.;
   x= datepart(x);
   put x= date9.;
run;&lt;/PRE&gt;
&lt;P&gt;If you do not change the format you will likely see "dates" that appear as similar to 01JAN1960:06:18:25&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>Fri, 12 May 2023 16:08:08 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-05-12T16:08:08Z</dc:date>
    <item>
      <title>Date part</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-part/m-p/875487#M345912</link>
      <description>&lt;P&gt;In a dataset I have a date values in the variable assign_date=01MAR2022:00:00:00 .I Need only 01MAR2022 in the variable.can anyone please help?.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to use substr(assign_date,1,9) but it gave some sas value date.-any reason why so?&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 15:47:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-part/m-p/875487#M345912</guid>
      <dc:creator>Akshaya_1397</dc:creator>
      <dc:date>2023-05-12T15:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: Date part</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-part/m-p/875489#M345913</link>
      <description>&lt;P&gt;In SAS, anything that has a time element cannot be a date. SAS dates are counts of days, times and datetimes are counts of seconds.&lt;/P&gt;
&lt;P&gt;To extract the date from a SAS datetime, you must use the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0rttbu7w62xgzn1damccyuwpld8.htm" target="_blank" rel="noopener"&gt;DATEPART&lt;/A&gt;&amp;nbsp;function.&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 16:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-part/m-p/875489#M345913</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-12T16:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Date part</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-part/m-p/875490#M345914</link>
      <description>&lt;P&gt;If this is the same data as in your earlier thread, the variable is numeric.&amp;nbsp;You can't use SUBSTR on numeric variables. SUBSTR only works on character variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;assign_date=datepart(assign_date);
format assign_date date9.; /* or any other date format you want */&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 May 2023 16:05:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-part/m-p/875490#M345914</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-12T16:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: Date part</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-part/m-p/875492#M345916</link>
      <description>&lt;P&gt;If the value is a SAS datetime value then "substr" would ask SAS to convert the underlying datetime value (which is typically a moderately large number of seconds) to character so that SUBSTR can be applied as shown in this log:&lt;/P&gt;
&lt;PRE&gt;1    data example;
2       x="01MAR2022:00:00:00"dt;
3       y=substr(x,1,9);
4    run;

NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
      3:13
&lt;/PRE&gt;
&lt;P&gt;Which has a result of 1961712, which are the first 9 characters of the value 1961712000 which is the number of seconds since midnight 01JAN1960 (or 01Jan1960:00:00:00).&lt;/P&gt;
&lt;P&gt;It appears that your value is a DATETIME value (type is numeric and the current format assigned to the variable is DATETIME19. (or longer).&lt;/P&gt;
&lt;P&gt;You want the DATEPART function to extract the value &lt;STRONG&gt;AND&lt;/STRONG&gt; to show the value as a date assign a&amp;nbsp;&lt;STRONG&gt;different&lt;/STRONG&gt; format such as DATE9&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   x="01MAR2022:00:00:00"dt;
   put x= datetime18.;
   x= datepart(x);
   put x= date9.;
run;&lt;/PRE&gt;
&lt;P&gt;If you do not change the format you will likely see "dates" that appear as similar to 01JAN1960:06:18:25&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>Fri, 12 May 2023 16:08:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-part/m-p/875492#M345916</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-12T16:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: Date part</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-part/m-p/875584#M345965</link>
      <description>&lt;P&gt;This method Worked out.thanks much!&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2023 10:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-part/m-p/875584#M345965</guid>
      <dc:creator>Akshaya_1397</dc:creator>
      <dc:date>2023-05-13T10:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Date part</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-part/m-p/875585#M345966</link>
      <description>&lt;P&gt;Thanks for the detailed explanation&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2023 10:10:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-part/m-p/875585#M345966</guid>
      <dc:creator>Akshaya_1397</dc:creator>
      <dc:date>2023-05-13T10:10:38Z</dc:date>
    </item>
  </channel>
</rss>

