<?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 Issue extracting year from date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Issue-extracting-year-from-date/m-p/851805#M336711</link>
    <description>&lt;P&gt;I import the data using proc import:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc import&lt;/P&gt;&lt;P&gt;datafile='/data/bvd/AcademicsSample.txt'&lt;BR /&gt;out=bvd.ac&lt;BR /&gt;dbms=dlm&lt;BR /&gt;replace;&lt;BR /&gt;delimiter = '09'x;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One of the extracted variables is Closing_date (proc contents result below):&lt;/P&gt;&lt;P&gt;# Variable&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Type Len Format&amp;nbsp; &amp;nbsp; Informat&lt;/P&gt;&lt;P&gt;4 Closing_date Num&amp;nbsp; 8&amp;nbsp; &amp;nbsp; BEST12. BEST32.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From proc print, I see the date as&amp;nbsp;20081231 for 31 December 2008.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Problem: I cannot extract the year from this date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using:&lt;/P&gt;&lt;P&gt;1) year=year(Closing_date); result is dots&amp;nbsp;(log NOTE: Invalid argument to function YEAR(20081231) at line 324 column 7.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2)&amp;nbsp;year=year(datepart(Closing_date)); result is 1960 for all observations&amp;nbsp;(no log NOTE)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) substr(Closing_date,1,4); result is blanks (log NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 324:14)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4) I have tried a bunch of other options that I found online but nothing worked, although I might not have executed these options well&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help!&lt;/P&gt;</description>
    <pubDate>Mon, 02 Jan 2023 10:28:25 GMT</pubDate>
    <dc:creator>Satori</dc:creator>
    <dc:date>2023-01-02T10:28:25Z</dc:date>
    <item>
      <title>Issue extracting year from date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-extracting-year-from-date/m-p/851805#M336711</link>
      <description>&lt;P&gt;I import the data using proc import:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc import&lt;/P&gt;&lt;P&gt;datafile='/data/bvd/AcademicsSample.txt'&lt;BR /&gt;out=bvd.ac&lt;BR /&gt;dbms=dlm&lt;BR /&gt;replace;&lt;BR /&gt;delimiter = '09'x;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One of the extracted variables is Closing_date (proc contents result below):&lt;/P&gt;&lt;P&gt;# Variable&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Type Len Format&amp;nbsp; &amp;nbsp; Informat&lt;/P&gt;&lt;P&gt;4 Closing_date Num&amp;nbsp; 8&amp;nbsp; &amp;nbsp; BEST12. BEST32.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From proc print, I see the date as&amp;nbsp;20081231 for 31 December 2008.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Problem: I cannot extract the year from this date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using:&lt;/P&gt;&lt;P&gt;1) year=year(Closing_date); result is dots&amp;nbsp;(log NOTE: Invalid argument to function YEAR(20081231) at line 324 column 7.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2)&amp;nbsp;year=year(datepart(Closing_date)); result is 1960 for all observations&amp;nbsp;(no log NOTE)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) substr(Closing_date,1,4); result is blanks (log NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 324:14)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4) I have tried a bunch of other options that I found online but nothing worked, although I might not have executed these options well&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help!&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2023 10:28:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-extracting-year-from-date/m-p/851805#M336711</guid>
      <dc:creator>Satori</dc:creator>
      <dc:date>2023-01-02T10:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Issue extracting year from date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-extracting-year-from-date/m-p/851806#M336712</link>
      <description>&lt;P&gt;This happens because SAS imports&amp;nbsp;&lt;SPAN&gt;Closing_date&amp;nbsp;as a plain number, not a SAS Date.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can do this to convert to a SAS Date&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   date = 20081231;

   newdate = input(put(date, 8.), yymmdd8.);
   year  = year(newdate);

   format newdate date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Jan 2023 10:27:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-extracting-year-from-date/m-p/851806#M336712</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2023-01-02T10:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Issue extracting year from date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-extracting-year-from-date/m-p/851807#M336713</link>
      <description>Thanks!</description>
      <pubDate>Mon, 02 Jan 2023 10:37:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-extracting-year-from-date/m-p/851807#M336713</guid>
      <dc:creator>Satori</dc:creator>
      <dc:date>2023-01-02T10:37:11Z</dc:date>
    </item>
  </channel>
</rss>

