<?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: Extracting the year from a character SAS variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extracting-the-year-from-a-character-SAS-variable/m-p/864173#M341292</link>
    <description>Thank you, this also worked. I saw the top one first. I appreciate your help!</description>
    <pubDate>Tue, 14 Mar 2023 22:02:10 GMT</pubDate>
    <dc:creator>ama220</dc:creator>
    <dc:date>2023-03-14T22:02:10Z</dc:date>
    <item>
      <title>Extracting the year from a character SAS variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-the-year-from-a-character-SAS-variable/m-p/862668#M340760</link>
      <description>&lt;P&gt;Hello: Any help with extracting the year from a SAS character variable&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE class="table" summary="Procedure Contents: Variables" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Latest_date_Date&lt;/TD&gt;
&lt;TD class="l data"&gt;Char&lt;/TD&gt;
&lt;TD class="r data"&gt;11&lt;/TD&gt;
&lt;TD class="l data"&gt;$11.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;example 08-mar-2001&lt;/P&gt;
&lt;P&gt;End result wanted is a new latest_year = 2001.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2023 14:45:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-the-year-from-a-character-SAS-variable/m-p/862668#M340760</guid>
      <dc:creator>ama220</dc:creator>
      <dc:date>2023-03-07T14:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the year from a character SAS variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-the-year-from-a-character-SAS-variable/m-p/862670#M340762</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;latest_year=year(input(Latest_date_Date, date11.));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Mar 2023 14:58:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-the-year-from-a-character-SAS-variable/m-p/862670#M340762</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-03-07T14:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the year from a character SAS variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-the-year-from-a-character-SAS-variable/m-p/862672#M340763</link>
      <description>&lt;P&gt;If all of the values follow that pattern then just take the 3rd (or last) word when using - as the delimiter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;latest_year = scan(latest_date_date,-1,'-');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that will create another character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want a number you could use INPUT() function to convert that string into a number.&lt;/P&gt;
&lt;P&gt;But in the case perhaps you should first use INPUT() to convert the date string into a date.&amp;nbsp; Then you could use the YEAR() function to take the year part of the date.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2023 15:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-the-year-from-a-character-SAS-variable/m-p/862672#M340763</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-07T15:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the year from a character SAS variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-the-year-from-a-character-SAS-variable/m-p/862780#M340801</link>
      <description>&lt;P&gt;Make your data intelligent by using SAS date values, then it's a breeze:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have (rename=(latest_date_date=_date));
latest_date_date = input(_date,date11.);
drop _date;
format latest_date_date date11.;
latest_year = year(latest_date_date);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Mar 2023 20:13:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-the-year-from-a-character-SAS-variable/m-p/862780#M340801</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-07T20:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the year from a character SAS variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-the-year-from-a-character-SAS-variable/m-p/864173#M341292</link>
      <description>Thank you, this also worked. I saw the top one first. I appreciate your help!</description>
      <pubDate>Tue, 14 Mar 2023 22:02:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-the-year-from-a-character-SAS-variable/m-p/864173#M341292</guid>
      <dc:creator>ama220</dc:creator>
      <dc:date>2023-03-14T22:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the year from a character SAS variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-the-year-from-a-character-SAS-variable/m-p/864174#M341293</link>
      <description>Thanks for the detailed response! This worked as well, but I saw the top one first and accepted as the solution.</description>
      <pubDate>Tue, 14 Mar 2023 22:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-the-year-from-a-character-SAS-variable/m-p/864174#M341293</guid>
      <dc:creator>ama220</dc:creator>
      <dc:date>2023-03-14T22:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the year from a character SAS variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-the-year-from-a-character-SAS-variable/m-p/864175#M341294</link>
      <description>Thanks for your help!!</description>
      <pubDate>Tue, 14 Mar 2023 22:03:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-the-year-from-a-character-SAS-variable/m-p/864175#M341294</guid>
      <dc:creator>ama220</dc:creator>
      <dc:date>2023-03-14T22:03:26Z</dc:date>
    </item>
  </channel>
</rss>

