<?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 format year in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/date-format-year/m-p/806398#M317700</link>
    <description>&lt;P&gt;So you have character variable that could have string up to 40 bytes long?&lt;/P&gt;
&lt;P&gt;And you want to convert that into a number that represents a year?&lt;/P&gt;
&lt;P&gt;Hopefully most of the values do not contain strings that are longer than 4 characters otherwise I am not sure what a year that large would mean.&lt;/P&gt;
&lt;P&gt;The INPUT() function is what you need to convert character strings into numbers.&amp;nbsp; The maximum length the numeric informat can handle is 32 bytes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;year=input(left(date),32.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to treat that as an actual date then you will need to pick some specific day within that year, such as January first.&lt;/P&gt;
&lt;P&gt;If you want to display just the year from this calculated date value you could attach the YEAR format to it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sas_date=mdy(1,1,year);
format sas_date year4.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 06 Apr 2022 20:55:51 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-04-06T20:55:51Z</dc:date>
    <item>
      <title>date format year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-format-year/m-p/806350#M317681</link>
      <description>&lt;P&gt;hello&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to transform date format to year&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data _7_Morningstar_Data2_expense;&lt;BR /&gt;set _7_Morningstar_Data_expense; &lt;BR /&gt;sas_date = input(put(date, 40.), YEAR.);&lt;BR /&gt;format sas_date YEAR.;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 17:14:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-format-year/m-p/806350#M317681</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2022-04-06T17:14:36Z</dc:date>
    </item>
    <item>
      <title>Re: date format year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-format-year/m-p/806351#M317682</link>
      <description>&lt;P&gt;Is variable DATE a true SAS date value? If so, all you need to do is assign format YEAR. to this variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the variable type and format according to PROC CONTENTS? Is it numeric? Or is it character? What format does it have? What are typical values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 17:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-format-year/m-p/806351#M317682</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-06T17:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: date format year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-format-year/m-p/806352#M317683</link>
      <description>&lt;P&gt;no date is&amp;nbsp;$40. format is not a date in SAS file I want to transform it to date format and it is in year like 1984; 1985 etc&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 17:21:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-format-year/m-p/806352#M317683</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2022-04-06T17:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: date format year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-format-year/m-p/806356#M317685</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4327"&gt;@sasphd&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;no date is&amp;nbsp;$40. format is not a date in SAS file I want to transform it to date format and it is in year like 1984; 1985 etc&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A date format would imply there is a year, month and day; but if you only have year, then just leave it as an integer. No formatting needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sas_date = put(strip(date), 4.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Apr 2022 17:29:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-format-year/m-p/806356#M317685</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-06T17:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: date format year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-format-year/m-p/806398#M317700</link>
      <description>&lt;P&gt;So you have character variable that could have string up to 40 bytes long?&lt;/P&gt;
&lt;P&gt;And you want to convert that into a number that represents a year?&lt;/P&gt;
&lt;P&gt;Hopefully most of the values do not contain strings that are longer than 4 characters otherwise I am not sure what a year that large would mean.&lt;/P&gt;
&lt;P&gt;The INPUT() function is what you need to convert character strings into numbers.&amp;nbsp; The maximum length the numeric informat can handle is 32 bytes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;year=input(left(date),32.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to treat that as an actual date then you will need to pick some specific day within that year, such as January first.&lt;/P&gt;
&lt;P&gt;If you want to display just the year from this calculated date value you could attach the YEAR format to it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sas_date=mdy(1,1,year);
format sas_date year4.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Apr 2022 20:55:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-format-year/m-p/806398#M317700</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-06T20:55:51Z</dc:date>
    </item>
  </channel>
</rss>

