<?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: Year function in data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Year-function-in-data-step/m-p/492671#M129506</link>
    <description>&lt;P&gt;Can you post a sample of your dataset period representing the values at best&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And any reason to convert date to char date using&amp;nbsp;&lt;SPAN&gt;put(date,datetime7.); ???&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 05 Sep 2018 14:20:13 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-09-05T14:20:13Z</dc:date>
    <item>
      <title>Year function in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-function-in-data-step/m-p/492669#M129505</link>
      <description>&lt;P&gt;I am trying to use the Year function to make a year variable using a date variable.&amp;nbsp; Below is the excerpt of the code I'm using, along with the error message I am getting.&amp;nbsp; &amp;nbsp; I have broken it up into different data steps as I've tried&amp;nbsp; a few different ways to get the Year function to work but haven't been able to get it to work.&amp;nbsp; &amp;nbsp; Could someone please provide some guidance?&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CODE:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data retained;&lt;BR /&gt;set period;&lt;BR /&gt;where date &amp;gt;= '1Jan2010:0:0:0'dt;&lt;BR /&gt;keep date;&lt;BR /&gt;&lt;BR /&gt;Data retained2;&lt;BR /&gt;set retained;&lt;BR /&gt;date1 = put(date,datetime7.);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Data retained3;&lt;BR /&gt;set retained2;&lt;BR /&gt;year = year(date1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR Message:&lt;/P&gt;&lt;P&gt;NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).&lt;BR /&gt;41:17&lt;BR /&gt;NOTE: Invalid numeric data, date1='01JAN15' , at line 41 column 17.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 14:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-function-in-data-step/m-p/492669#M129505</guid>
      <dc:creator>KenH</dc:creator>
      <dc:date>2018-09-05T14:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: Year function in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-function-in-data-step/m-p/492671#M129506</link>
      <description>&lt;P&gt;Can you post a sample of your dataset period representing the values at best&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And any reason to convert date to char date using&amp;nbsp;&lt;SPAN&gt;put(date,datetime7.); ???&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 14:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-function-in-data-step/m-p/492671#M129506</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-05T14:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: Year function in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-function-in-data-step/m-p/492674#M129508</link>
      <description>&lt;P&gt;The put function always renders character as its result. What you need is a SAS date value, which is a count of days from 1960-01-01:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data retained;
set period;
where date &amp;gt;= '1Jan2010:0:0:0'dt;
year = year(datepart(date));
keep date year;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The datepart() function creates the SAS date value from the SAS datetime value.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 14:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-function-in-data-step/m-p/492674#M129508</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-05T14:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: Year function in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-function-in-data-step/m-p/492678#M129510</link>
      <description>&lt;P&gt;awesome, that works.&amp;nbsp; Thanks so much!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 14:28:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-function-in-data-step/m-p/492678#M129510</guid>
      <dc:creator>KenH</dc:creator>
      <dc:date>2018-09-05T14:28:00Z</dc:date>
    </item>
  </channel>
</rss>

