<?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: converting character date value to year4. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/converting-character-date-value-to-year4/m-p/524043#M142460</link>
    <description>&lt;P&gt;Use the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0jshdjy2z9zdzn1h7k90u99lyq6.htm&amp;amp;locale=de" target="_blank"&gt;scan()&lt;/A&gt; function to retrieve the third "word" (separated by slashes), and the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p19en16vskd2vhn1vwmxpxnglxxs.htm&amp;amp;locale=de" target="_blank"&gt;input()&lt;/A&gt; function to convert the string to numeric.&lt;/P&gt;</description>
    <pubDate>Wed, 02 Jan 2019 09:10:02 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-01-02T09:10:02Z</dc:date>
    <item>
      <title>converting character date value to year4.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-date-value-to-year4/m-p/524037#M142456</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset in which the birth date variable is in character format and some of the values do not have the birth month and birth date. Hence, I need to create a new variable in my dataset and just extract the birth year alone. Here is the snippet of the dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 179px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25933iF4F99AAE717ADD3D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could anyone please help me on how to create a new variable for the birth month alone.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jan 2019 08:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-date-value-to-year4/m-p/524037#M142456</guid>
      <dc:creator>sheren_deep1</dc:creator>
      <dc:date>2019-01-02T08:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: converting character date value to year4.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-date-value-to-year4/m-p/524039#M142458</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use the function SUBSTR if all vaues have the same format / layout.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/imlug/66845/HTML/default/viewer.htm#imlug_langref_sect455.htm" target="_self"&gt;SUBSTR Function&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jan 2019 08:29:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-date-value-to-year4/m-p/524039#M142458</guid>
      <dc:creator>DJongman</dc:creator>
      <dc:date>2019-01-02T08:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: converting character date value to year4.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-date-value-to-year4/m-p/524043#M142460</link>
      <description>&lt;P&gt;Use the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0jshdjy2z9zdzn1h7k90u99lyq6.htm&amp;amp;locale=de" target="_blank"&gt;scan()&lt;/A&gt; function to retrieve the third "word" (separated by slashes), and the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p19en16vskd2vhn1vwmxpxnglxxs.htm&amp;amp;locale=de" target="_blank"&gt;input()&lt;/A&gt; function to convert the string to numeric.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jan 2019 09:10:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-date-value-to-year4/m-p/524043#M142460</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-02T09:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: converting character date value to year4.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-date-value-to-year4/m-p/524051#M142465</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length DOB $32.;
input DOB $;
informat DOB $32.;
datalines;
01/01/1980
01/12/1960
02/01/2019
31/12/2018
;
run;

proc contents data=work.have;
run;

data want;
set have;
new_year=year(input(DOB,ddmmyy10.));
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Jan 2019 11:06:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-date-value-to-year4/m-p/524051#M142465</guid>
      <dc:creator>Riteshdell</dc:creator>
      <dc:date>2019-01-02T11:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: converting character date value to year4.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-date-value-to-year4/m-p/524067#M142477</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/6813"&gt;@Riteshdell&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length DOB $32.;
input DOB $;
informat DOB $32.;
datalines;
01/01/1980
01/12/1960
02/01/2019
31/12/2018
;
run;

proc contents data=work.have;
run;

data want;
set have;
new_year=year(input(DOB,ddmmyy10.));
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does not work with the data provided by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/113092"&gt;@sheren_deep1&lt;/a&gt; - if month and day are zero (see first line of the data posted) the format ddmmyy is unabble to create a date, so that year() returns missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using scan+input (as suggested by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;), seems be the easiest way to solve the problem:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   new_year = input(scan(DOB, 3, '/'), 4.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Jan 2019 12:26:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-date-value-to-year4/m-p/524067#M142477</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-01-02T12:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: converting character date value to year4.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-date-value-to-year4/m-p/524218#M142532</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks all for the help. I manage to do it with the substr function.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2019 03:05:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-date-value-to-year4/m-p/524218#M142532</guid>
      <dc:creator>sheren_deep1</dc:creator>
      <dc:date>2019-01-03T03:05:51Z</dc:date>
    </item>
  </channel>
</rss>

