<?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 How to convert text to numeric date? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-convert-text-to-numeric-date/m-p/552797#M9235</link>
    <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;I used "proc sort data= alldata0001;&lt;BR /&gt;by Company_Name Annual_Report_Year ; run;"&lt;/P&gt;&lt;P&gt;to combine several sets together, however Annual_Report_Year in the original file is text not numeric date...&lt;/P&gt;&lt;P&gt;and all my sorting are messed up, as you can see from the attached photo, Apr 2016, Apr 2017 come before Mar 2000 and Mar 2002...&lt;/P&gt;&lt;P&gt;Anyone know how to use sas codes to convert text to numeric date in this case?&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="q.jpg" style="width: 428px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28856i06C3B899FCDAE297/image-size/large?v=v2&amp;amp;px=999" role="button" title="q.jpg" alt="q.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Apr 2019 11:51:20 GMT</pubDate>
    <dc:creator>LydiaSmith</dc:creator>
    <dc:date>2019-04-22T11:51:20Z</dc:date>
    <item>
      <title>How to convert text to numeric date?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-convert-text-to-numeric-date/m-p/552797#M9235</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;I used "proc sort data= alldata0001;&lt;BR /&gt;by Company_Name Annual_Report_Year ; run;"&lt;/P&gt;&lt;P&gt;to combine several sets together, however Annual_Report_Year in the original file is text not numeric date...&lt;/P&gt;&lt;P&gt;and all my sorting are messed up, as you can see from the attached photo, Apr 2016, Apr 2017 come before Mar 2000 and Mar 2002...&lt;/P&gt;&lt;P&gt;Anyone know how to use sas codes to convert text to numeric date in this case?&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="q.jpg" style="width: 428px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28856i06C3B899FCDAE297/image-size/large?v=v2&amp;amp;px=999" role="button" title="q.jpg" alt="q.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 11:51:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-convert-text-to-numeric-date/m-p/552797#M9235</guid>
      <dc:creator>LydiaSmith</dc:creator>
      <dc:date>2019-04-22T11:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert text to numeric date?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-convert-text-to-numeric-date/m-p/552801#M9238</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;numdate = input('01' !! compress(chardate),date9.);
format numdate date9.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;compress() removes the blank, and '01' completes the string to a date.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 12:04:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-convert-text-to-numeric-date/m-p/552801#M9238</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-22T12:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert text to numeric date?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-convert-text-to-numeric-date/m-p/552803#M9239</link>
      <description>&lt;P&gt;Check next code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    text = "APR 2016";
    date = input(cat('01',strip(text)),daye9.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but for merging by date, are all your dates at 01 day of a month ?&lt;/P&gt;
&lt;P&gt;May be you need create a separate variable key for merging, excluding the day:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sortby = put(date, yymmddn6.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 12:08:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-convert-text-to-numeric-date/m-p/552803#M9239</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-04-22T12:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert text to numeric date?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-convert-text-to-numeric-date/m-p/552913#M9259</link>
      <description>&lt;P&gt;&lt;FONT color="#000000"&gt;Mr. &lt;SPAN class="UserName lia-user-name lia-user-rank-Super-User"&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562" target="_self"&gt;&lt;SPAN class="login-bold"&gt;Bremser&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Thank you so much for your reply! I really appreciate your help!!&lt;/P&gt;&lt;P&gt;However, it did not work out...the result is blank...&lt;/P&gt;&lt;P&gt;I don't know where I did wrong...&lt;/P&gt;&lt;P&gt;I attached my test file for your reference!&lt;/P&gt;&lt;P&gt;The date under&amp;nbsp;Annual_Report_Year is literal text, not shortened variable from actual date...&lt;/P&gt;&lt;P&gt;Thank you again!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="q1.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28889iFAF83BE51F3DFFB7/image-size/large?v=v2&amp;amp;px=999" role="button" title="q1.jpg" alt="q1.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 15:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-convert-text-to-numeric-date/m-p/552913#M9259</guid>
      <dc:creator>LydiaSmith</dc:creator>
      <dc:date>2019-04-22T15:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert text to numeric date?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-convert-text-to-numeric-date/m-p/552916#M9260</link>
      <description>&lt;P&gt;&lt;FONT color="#000000"&gt;Mr. &lt;SPAN class="UserName lia-user-name lia-user-rank-Super-User"&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384" target="_self"&gt;Shmuel&lt;/A&gt;&lt;/SPAN&gt;,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Thank you so much for your reply! Your help is appreciated!&lt;/P&gt;&lt;P&gt;I've tried with your code then changed "text" to "Annual_Report_Year,"&lt;/P&gt;&lt;P&gt;But the result displayed only APR 2016, still in text form...&lt;/P&gt;&lt;P&gt;The date (APR 2016) under&amp;nbsp;Annual_Report_Year is literal text, not shortened variable from actual date, so no day of the month either...&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My goal is to convert all the literal date to numerical date, APR 2016 to 201604, so I could sort my combined data sets in the right annual order.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;So maybe I need to try another way to convert it?&lt;/P&gt;&lt;P&gt;I attached my test file for your reference, thank you again!&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="q2.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28890i5FBD7AA9A1348D79/image-size/large?v=v2&amp;amp;px=999" role="button" title="q2.jpg" alt="q2.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 15:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-convert-text-to-numeric-date/m-p/552916#M9260</guid>
      <dc:creator>LydiaSmith</dc:creator>
      <dc:date>2019-04-22T15:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert text to numeric date?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-convert-text-to-numeric-date/m-p/552928#M9264</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271447"&gt;@LydiaSmith&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;Mr. &lt;SPAN class="UserName lia-user-name lia-user-rank-Super-User"&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384" target="_self"&gt;Shmuel&lt;/A&gt;&lt;/SPAN&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;My goal is to convert all the literal date to numerical date, APR 2016 to 201604, so I could sort my combined data sets in the right annual order.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Poor choice. SAS has it's own numeric date values which are MUCH more flexible. You apply any one of a number of Formats (or create your own) to display or group dates as desired. There are a number of functions to manipulate the SAS date values. And the SAS date values will sort consistently .&lt;/P&gt;
&lt;P&gt;I might try using the ANYDTDTE. format to read that date.&lt;/P&gt;
&lt;PRE&gt;data test;
  x='Apr 2016';
  y=input(x,anydtdte.);
  put y= date9. y=mmddyy10. y=yymmn6.;
run;&lt;/PRE&gt;
&lt;P&gt;The default will be for SAS to make the day of the month the&amp;nbsp; first. Note that I demonstrate 3 of several possible formats to display the date value. With a SAS date value you change the appearance as needed just by using a different format, either in a report or analysis procedures. Most of the analysis and graphing procedures will honor groups created by use of a format. With formats that can group calendar quarters, such as YYQ, or simple years using the YEAR format you can gain a lot of flexibility that would otherwise require adding additional variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One example: how many days are between the 201604&amp;nbsp; (first of april) and 202008 (first of august)? How many weeks? You can't do simple arithmetic to get either answer but SAS functions working with date values can.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 16:15:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-convert-text-to-numeric-date/m-p/552928#M9264</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-22T16:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert text to numeric date?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-convert-text-to-numeric-date/m-p/552953#M9270</link>
      <description>&lt;P&gt;Your dataset does not contain a variable chardate. I used this name only for a simple example, as you did not provide example data in usable form (data step with datalines).&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 17:27:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-convert-text-to-numeric-date/m-p/552953#M9270</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-22T17:27:44Z</dc:date>
    </item>
  </channel>
</rss>

