<?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 to numeric form if only year and month are provided in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/converting-character-date-to-numeric-form-if-only-year-and-month/m-p/277966#M55883</link>
    <description>&lt;P&gt;aestdt = input( cats(date, '-01-01'), yymmdd10.);&lt;/P&gt;
&lt;P&gt;format aestdt yymmdd10.;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Jun 2016 16:51:56 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-06-16T16:51:56Z</dc:date>
    <item>
      <title>converting character date to numeric form if only year and month are provided</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-date-to-numeric-form-if-only-year-and-month/m-p/277963#M55881</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my data, for some of the date values &amp;nbsp;only year and month and for some only year are provided. what informat I need to use to convert to numeric form.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATE&lt;/P&gt;&lt;P&gt;2016-06-12&lt;/P&gt;&lt;P&gt;2016-06&lt;/P&gt;&lt;P&gt;2016&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use the code: I am not getting the output for observation 2 and 3. &amp;nbsp;For 2 and 3 observations, i need 2016-06-01 and 2016-01-01 as my output. Please help. Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;date1=input(date, yymmdd10.);&lt;/P&gt;&lt;P&gt;format AESTDT yymmdd10.;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 16:47:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-date-to-numeric-form-if-only-year-and-month/m-p/277963#M55881</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2016-06-16T16:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: converting character date to numeric form if only year and month are provided</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-date-to-numeric-form-if-only-year-and-month/m-p/277966#M55883</link>
      <description>&lt;P&gt;aestdt = input( cats(date, '-01-01'), yymmdd10.);&lt;/P&gt;
&lt;P&gt;format aestdt yymmdd10.;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 16:51:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-date-to-numeric-form-if-only-year-and-month/m-p/277966#M55883</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-16T16:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: converting character date to numeric form if only year and month are provided</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-date-to-numeric-form-if-only-year-and-month/m-p/277982#M55890</link>
      <description>&lt;P&gt;Thanks for the help. If I have to convert 2016-06(CHARARCTER) to numeric form 2016-06 what is the informat I have to use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;date1=informat(DATE,?);&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been looking in SAS material. I could not find it. How to convert. Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 17:44:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-date-to-numeric-form-if-only-year-and-month/m-p/277982#M55890</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2016-06-16T17:44:37Z</dc:date>
    </item>
    <item>
      <title>Re: converting character date to numeric form if only year and month are provided</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-date-to-numeric-form-if-only-year-and-month/m-p/277983#M55891</link>
      <description>&lt;P&gt;You would use exactly what I posted.&amp;nbsp; Informats always read a character string (whether or not the character string contains digits).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no such thing in SAS as a numeric form 2016-06.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 17:49:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-date-to-numeric-form-if-only-year-and-month/m-p/277983#M55891</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-16T17:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: converting character date to numeric form if only year and month are provided</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-date-to-numeric-form-if-only-year-and-month/m-p/278004#M55899</link>
      <description>&lt;P&gt;Once again Thank you very much. But that did not help me for my output. The following what i been trying.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I been trying to derive date1 from date and date3 variables&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If date is complete then date1=date (observation1);&lt;/P&gt;&lt;P&gt;if only year and month provided in date variable then compare date variable month to date2 variable month. If monthes are equal then date1=date2(&lt;SPAN&gt;observation3)&lt;/SPAN&gt;; else date1=first day of month(&lt;SPAN&gt;observation2).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if only year provided, then compare with&amp;nbsp;date variable year to date2 variable year. If years are equal then date1=date2(&lt;SPAN&gt;observation5)&lt;/SPAN&gt;&lt;SPAN&gt;; else date1=first day of year(&lt;/SPAN&gt;&lt;SPAN&gt;observation4). please help. Thank you.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;date(Character) &amp;nbsp; &amp;nbsp;date1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;date2(numeric)&lt;BR /&gt;2015-06-03 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2015-06-03 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2015-02-03&lt;/P&gt;&lt;P&gt;2015-06 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2015-06-01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2015-05-04&lt;/P&gt;&lt;P&gt;2015-05 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2015-05-04 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2015-05-04&lt;/P&gt;&lt;P&gt;2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2015-01-01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2014-04-04&lt;/P&gt;&lt;P&gt;2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2015-02-01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2015-02-01&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 18:40:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-date-to-numeric-form-if-only-year-and-month/m-p/278004#M55899</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2016-06-16T18:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: converting character date to numeric form if only year and month are provided</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-date-to-numeric-form-if-only-year-and-month/m-p/278008#M55901</link>
      <description>&lt;P&gt;OK, here's a possibility ... within the context of a DATA step ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if length(date)=10 then date1 = input(date, yymmdd10.);&lt;/P&gt;
&lt;P&gt;else do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if trim(date) =: put(date2, yymmddd10.) then date1 = date2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; else date1 = input( cats(date, '-01-01'), yymmdd10.);&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;format date1 yymmddd10.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's untested, so it might need a little debugging.&amp;nbsp; Note a couple of items about the ELSE DO statement.&amp;nbsp; It assumes that you will always have something in DATE.&amp;nbsp; If it might be blank, that's another condition that needs to be accounted for.&amp;nbsp; Also, it's tricky but handles both cases (year + month, or just the year).&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 18:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-date-to-numeric-form-if-only-year-and-month/m-p/278008#M55901</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-16T18:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: converting character date to numeric form if only year and month are provided</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-date-to-numeric-form-if-only-year-and-month/m-p/278010#M55903</link>
      <description>&lt;P&gt;Great. Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 19:34:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-date-to-numeric-form-if-only-year-and-month/m-p/278010#M55903</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2016-06-16T19:34:01Z</dc:date>
    </item>
  </channel>
</rss>

