<?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: convert datetime to numeric value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/convert-datetime-to-numeric-value/m-p/411235#M279700</link>
    <description>&lt;P&gt;The DTYEAR format is used to print a datetime value as only the year. It does not change the value that is stored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can either compare the formatted value to the string value of the year or&amp;nbsp;extract the year from the datetime value as number and compare it the numeric value of the year. So you could calculate your boolean FLAG variable this way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;flag = '2012' = put(date,dtyear4.) ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or this way.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format date dtyear4.;
flag = '2012' = vvalue(date) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or this way.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;flag = 2012 = year(datepart(date)) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Nov 2017 16:21:02 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-11-07T16:21:02Z</dc:date>
    <item>
      <title>convert datetime to numeric value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-datetime-to-numeric-value/m-p/411229#M279698</link>
      <description>&lt;P&gt;I have a date time field DATETIME20 which I converted to DTYEAR4. I would now like to use the year to give a flag of 0 or 1 if present. So for instance '7/23/2012 00:03:09'dt to 2012 to 2012 is present=1, else 0. Can I not just now use 2012 in the code?&lt;/P&gt;&lt;P&gt;I've used the following code but it doesn't work, thx.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new;&amp;nbsp;&lt;/P&gt;&lt;P&gt;format date dtyear4;&lt;/P&gt;&lt;P&gt;if date=2012 then flag=1; else flag =0&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 16:12:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-datetime-to-numeric-value/m-p/411229#M279698</guid>
      <dc:creator>jsandsk</dc:creator>
      <dc:date>2017-11-07T16:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: convert datetime to numeric value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-datetime-to-numeric-value/m-p/411234#M279699</link>
      <description>&lt;P&gt;No, the underlying value is still a datetime, a FORMAT just controls the appearance of the variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can convert it using DATEPART and YEAR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if year(datepart(variable)) = 2012 ...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Nov 2017 16:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-datetime-to-numeric-value/m-p/411234#M279699</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-07T16:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: convert datetime to numeric value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-datetime-to-numeric-value/m-p/411235#M279700</link>
      <description>&lt;P&gt;The DTYEAR format is used to print a datetime value as only the year. It does not change the value that is stored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can either compare the formatted value to the string value of the year or&amp;nbsp;extract the year from the datetime value as number and compare it the numeric value of the year. So you could calculate your boolean FLAG variable this way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;flag = '2012' = put(date,dtyear4.) ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or this way.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format date dtyear4.;
flag = '2012' = vvalue(date) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or this way.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;flag = 2012 = year(datepart(date)) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 16:21:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-datetime-to-numeric-value/m-p/411235#M279700</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-07T16:21:02Z</dc:date>
    </item>
  </channel>
</rss>

