<?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 in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/DATE/m-p/652854#M22464</link>
    <description>&lt;P&gt;How do I pull the 4 digit year out of this&amp;nbsp;25MAY2015:00:00:00&amp;nbsp; in SAS?&lt;/P&gt;&lt;P&gt;I want to create a column year with the year of the transaction&lt;/P&gt;&lt;P&gt;I tried several different combos...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;format&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year&amp;nbsp;&amp;nbsp;YEAR4.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year = substr(transact_date,&lt;STRONG&gt;5&lt;/STRONG&gt;,&lt;STRONG&gt;4&lt;/STRONG&gt;);&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I changed year to transact_year&lt;/P&gt;&lt;P&gt;23OCT2018:00:00:00.00000&amp;nbsp; is the transact_date in the results and it gives me 1975 as the year&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jun 2020 12:55:38 GMT</pubDate>
    <dc:creator>bweeks59</dc:creator>
    <dc:date>2020-06-03T12:55:38Z</dc:date>
    <item>
      <title>DATE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DATE/m-p/652854#M22464</link>
      <description>&lt;P&gt;How do I pull the 4 digit year out of this&amp;nbsp;25MAY2015:00:00:00&amp;nbsp; in SAS?&lt;/P&gt;&lt;P&gt;I want to create a column year with the year of the transaction&lt;/P&gt;&lt;P&gt;I tried several different combos...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;format&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year&amp;nbsp;&amp;nbsp;YEAR4.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year = substr(transact_date,&lt;STRONG&gt;5&lt;/STRONG&gt;,&lt;STRONG&gt;4&lt;/STRONG&gt;);&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I changed year to transact_year&lt;/P&gt;&lt;P&gt;23OCT2018:00:00:00.00000&amp;nbsp; is the transact_date in the results and it gives me 1975 as the year&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 12:55:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DATE/m-p/652854#M22464</guid>
      <dc:creator>bweeks59</dc:creator>
      <dc:date>2020-06-03T12:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: DATE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DATE/m-p/652856#M22465</link>
      <description>&lt;P&gt;Assuming your datetime value is numeric,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; year = year(datepart(transact_date)); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also consider just formatting the datetime numeric value of transact_date to &lt;STRONG&gt;display &lt;/STRONG&gt;only the year values by using &lt;STRONG&gt;dtyear&lt;/STRONG&gt; format&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format  transact_date dtyear.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jun 2020 13:07:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DATE/m-p/652856#M22465</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-06-03T13:07:06Z</dc:date>
    </item>
    <item>
      <title>Re: DATE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DATE/m-p/652858#M22466</link>
      <description>&lt;P&gt;And if your datetime value is char, then&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;year=year(input(transact_date,date9.));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jun 2020 13:03:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DATE/m-p/652858#M22466</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-06-03T13:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: DATE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DATE/m-p/652862#M22467</link>
      <description>&lt;P&gt;Or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;year = input(put(transact_date,dtyear4.),4.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;if you have a SAS datetime value.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 13:07:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DATE/m-p/652862#M22467</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-03T13:07:51Z</dc:date>
    </item>
    <item>
      <title>Re: DATE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DATE/m-p/652867#M22468</link>
      <description>&lt;P&gt;SAS stores dates as number of days and datetimes as number of seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The YEAR format is for DATE values, not DATETIME values.&amp;nbsp; If you try to use it with a date value well into the future since there a 86,400 seconds in a single day.&lt;/P&gt;
&lt;P&gt;The SUBSTR() function is for character values, not numeric values.&amp;nbsp; If you try to apply it to a numeric value SAS will first convert the number to a string using the BEST12. format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you convert the datetime value to a datevalue you can use the YEAR format to display it as the year number.&amp;nbsp; Or you could use the YEAR() function to extract the year as a number in years.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have (rename=(transact_date=transact_datetime));
  transact_date=datepart(transact_datetime);
  transact_year=year(transact_date);
  format transact_date date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jun 2020 13:12:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DATE/m-p/652867#M22468</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-06-03T13:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: DATE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DATE/m-p/652868#M22469</link>
      <description>Thanks for the quick reply, I will try the methods you have listed and let you know how it goes.</description>
      <pubDate>Wed, 03 Jun 2020 13:13:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DATE/m-p/652868#M22469</guid>
      <dc:creator>bweeks59</dc:creator>
      <dc:date>2020-06-03T13:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: DATE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DATE/m-p/652870#M22470</link>
      <description>Yes the date is a SAS datetime value, I am working on a few methods to see which one produces the required result and will let you know if i have success:-) Thanks a bunch</description>
      <pubDate>Wed, 03 Jun 2020 13:16:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DATE/m-p/652870#M22470</guid>
      <dc:creator>bweeks59</dc:creator>
      <dc:date>2020-06-03T13:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: DATE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DATE/m-p/652876#M22472</link>
      <description>&lt;P&gt;This worked and fast too:-) thanks so much for everyone's help....&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 13:35:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DATE/m-p/652876#M22472</guid>
      <dc:creator>bweeks59</dc:creator>
      <dc:date>2020-06-03T13:35:32Z</dc:date>
    </item>
  </channel>
</rss>

