<?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: Process textual date data removing invalid parts in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Process-textual-date-data-removing-invalid-parts/m-p/506400#M135754</link>
    <description>&lt;P&gt;I think that what you want is something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set date1;
  if length(date1)=9 then
    if input(date1,?? date9.)=. then
	  date1=substr(date1,3);
  if length(date1)=7 then
    if input(date1,?? monyy7.)=. then
	  date1=substr(date1,4);
  if length(date1)=4 then
    if input(date1,?? 4.)=. then
	  date1='.';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Note the lack of ELSE statements: for once, it is intended (e.g. "ununk2018" is first shortened to "unk2018" and then to "2018").&lt;/P&gt;</description>
    <pubDate>Mon, 22 Oct 2018 11:47:36 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2018-10-22T11:47:36Z</dc:date>
    <item>
      <title>Process textual date data removing invalid parts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Process-textual-date-data-removing-invalid-parts/m-p/506370#M135733</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hi i am having the data like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data date1;&lt;BR /&gt;input date1 $ 12.;&lt;BR /&gt;cards;&lt;BR /&gt;30oct2016&lt;BR /&gt;12jun2018&lt;BR /&gt;oct2016&lt;BR /&gt;2016&lt;BR /&gt;unk2016&lt;BR /&gt;ununk2017&lt;BR /&gt;ukoct2018&lt;BR /&gt;uuuu&lt;BR /&gt;unun&lt;BR /&gt;01unk2020&lt;BR /&gt;01jan2017&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i need report as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;30oct2016&lt;/P&gt;
&lt;P&gt;12jun2018&lt;/P&gt;
&lt;P&gt;oct2016&lt;/P&gt;
&lt;P&gt;2016&lt;/P&gt;
&lt;P&gt;2016&lt;/P&gt;
&lt;P&gt;2017&lt;/P&gt;
&lt;P&gt;oct2018&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;2020&lt;/P&gt;
&lt;P&gt;01jan2017&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i want like this can any one help me&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 09:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Process-textual-date-data-removing-invalid-parts/m-p/506370#M135733</guid>
      <dc:creator>ravindra2</dc:creator>
      <dc:date>2018-10-22T09:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: Process textual date data removing invalid parts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Process-textual-date-data-removing-invalid-parts/m-p/506377#M135738</link>
      <description>&lt;P&gt;You can use the function tranwrd to remove parts from a string:&lt;/P&gt;
&lt;PRE&gt;data want;
  set date1;
  date=tranwrd(date,"unk","");
  date=tranwrd(date,"uuuu","");
  date=tranwrd(date,"uk","");
  date=strip(compress(date));
run;
&lt;/PRE&gt;
&lt;P&gt;However I am not sure why you have "." in for missings, this is text we are talking about here, dates would need to have&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;all&lt;/STRONG&gt;&lt;/U&gt; parts of the date to be convertable to date format.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 09:48:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Process-textual-date-data-removing-invalid-parts/m-p/506377#M135738</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-22T09:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: using functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Process-textual-date-data-removing-invalid-parts/m-p/506379#M135740</link>
      <description>&lt;P&gt;Try truncate any leading 'u' or 'n' characters, using a loop until first character not in those letters:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;len = length(date);
ch = substr(date,1,1);
do while (ch in ('u', 'n') and len &amp;gt; 0);&lt;BR /&gt;   if substr(date,1,3) = 'nov' then leave;
     date = substr(date,2);
     len - 1; 
    ch = substr(date,1,1);
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Oct 2018 10:35:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Process-textual-date-data-removing-invalid-parts/m-p/506379#M135740</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-10-22T10:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: Process textual date data removing invalid parts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Process-textual-date-data-removing-invalid-parts/m-p/506400#M135754</link>
      <description>&lt;P&gt;I think that what you want is something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set date1;
  if length(date1)=9 then
    if input(date1,?? date9.)=. then
	  date1=substr(date1,3);
  if length(date1)=7 then
    if input(date1,?? monyy7.)=. then
	  date1=substr(date1,4);
  if length(date1)=4 then
    if input(date1,?? 4.)=. then
	  date1='.';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Note the lack of ELSE statements: for once, it is intended (e.g. "ununk2018" is first shortened to "unk2018" and then to "2018").&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 11:47:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Process-textual-date-data-removing-invalid-parts/m-p/506400#M135754</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-10-22T11:47:36Z</dc:date>
    </item>
  </channel>
</rss>

