<?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: More Elegant Way To Replace UNK and UN In Date Values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/806939#M318026</link>
    <description>&lt;P&gt;Fundamentally, I think you want to convert the character string dates to actual numeric SAS dates, rather than make them character strings that look like dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But since you don't give us examples of the input data, I can't be more specific.&lt;/P&gt;</description>
    <pubDate>Sat, 09 Apr 2022 16:09:14 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-04-09T16:09:14Z</dc:date>
    <item>
      <title>More Elegant Way To Replace UNK and UN In Date Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/806937#M318025</link>
      <description>Dear all,&lt;BR /&gt;I'm working with the data, which contains dates with missing either month (replaced with UNK) or day (replaced with UN).&lt;BR /&gt;UPD: the values look like this: 2022JAN15, 2022JANUN and 2022UNKUN.&lt;BR /&gt;I have seen multiple posts on the same topic, but I'm still in pursue of the most elegant solutions.&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;I have made it following:&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;date_new=tranwrd(tranwrd(upcase(date), 'UNK', 'JAN'), 'UN', '01');&lt;BR /&gt;run;&lt;BR /&gt;I wonder if it's possible to make with PRXCHNAGE:&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;date_new=prxchange('s/(\d{4})((?(?=U)UNK|(\w{3})))((?(?=U)UN|(\d{2})))/$1 $3 $5/i',&lt;BR /&gt;-1, AE.aestdat);&lt;BR /&gt;run;&lt;BR /&gt;But it fails to put JAN or 01, if the condition is met. Replace portions of the PRXCHANGE doesn't accept " | " as OR.&lt;BR /&gt;Thank you in advance for your help and advice!&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;&amp;amp;nbsp;</description>
      <pubDate>Sat, 09 Apr 2022 16:11:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/806937#M318025</guid>
      <dc:creator>klchtsk</dc:creator>
      <dc:date>2022-04-09T16:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: More Elegant Way To Replace UNK and UN In Date Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/806939#M318026</link>
      <description>&lt;P&gt;Fundamentally, I think you want to convert the character string dates to actual numeric SAS dates, rather than make them character strings that look like dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But since you don't give us examples of the input data, I can't be more specific.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Apr 2022 16:09:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/806939#M318026</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-09T16:09:14Z</dc:date>
    </item>
    <item>
      <title>Re: More Elegant Way To Replace UNK and UN In Date Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/806941#M318028</link>
      <description>Thank you for your reply! Sorry for not putting it in a first place. I have added an update to the original message. The values look like this: 2022JAN15, 2022JANUN and 2022UNKUN.</description>
      <pubDate>Sat, 09 Apr 2022 16:12:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/806941#M318028</guid>
      <dc:creator>klchtsk</dc:creator>
      <dc:date>2022-04-09T16:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: More Elegant Way To Replace UNK and UN In Date Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/806944#M318030</link>
      <description>&lt;P&gt;I would steal your earlier code, and modify it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date_new=input(tranwrd(tranwrd(upcase(date), 'UNK', 'JAN'), 'UN', '01'),anydtdte.);
format date_new date9.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Apr 2022 19:32:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/806944#M318030</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-09T19:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: More Elegant Way To Replace UNK and UN In Date Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/806946#M318032</link>
      <description>Thank you for your reply! I'm pleased that you have used my code! Any chance PRXCHANGE can be make it in one run without double TRANWRD? I'm just mesmerized by this function! Thank you!</description>
      <pubDate>Sat, 09 Apr 2022 19:41:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/806946#M318032</guid>
      <dc:creator>klchtsk</dc:creator>
      <dc:date>2022-04-09T19:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: More Elegant Way To Replace UNK and UN In Date Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/806947#M318033</link>
      <description>&lt;P&gt;I'm sure the prschange experts can advise, but I am not one of them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Those are odd dates, with year, then month, then day.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Apr 2022 20:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/806947#M318033</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-09T20:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: More Elegant Way To Replace UNK and UN In Date Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/806959#M318037</link>
      <description>&lt;P&gt;The nested TRANWRDs put forth by the OP would improperly process "JUN" in the month component, so text like&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;2001JUN15 would be converted to 2001J0115 prior to a failed attempt to convert it to a date value, as below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do date='2001FEBUN','2001UNKUN','2001UNK15','2001MAR15',  '2001JUN15';
    date_new=input(tranwrd(tranwrd(upcase(date), 'UNK', 'JAN'), 'UN', '01'),anydtdte.);
    format date_new date9.;
    put (_all_) (=);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But append a "!" to the DATE text, allows TRANWRD&amp;nbsp; "UN!" to "01!", which avoids the "JUN" problem:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do date='2001FEBUN','2001UNKUN','2001UNK15','2001MAR15',  '2001JUN15';
    date_new=input(tranwrd(tranwrd(upcase(cats(date,'!')), 'UNK', 'JAN'), 'UN!', '01!'),anydtdte.);
    format date_new date9.;
    put (_all_) (=);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Apr 2022 23:09:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/806959#M318037</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-04-09T23:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: More Elegant Way To Replace UNK and UN In Date Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/807225#M318210</link>
      <description>Thank you very much for the answer!</description>
      <pubDate>Mon, 11 Apr 2022 18:50:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/807225#M318210</guid>
      <dc:creator>klchtsk</dc:creator>
      <dc:date>2022-04-11T18:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: More Elegant Way To Replace UNK and UN In Date Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/807227#M318211</link>
      <description>You are completely right, that I have strayed further from the whole point of data transformation. I should focus of calculation of intervals using the data I have but not on transformation I do not need!</description>
      <pubDate>Mon, 11 Apr 2022 18:51:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-Elegant-Way-To-Replace-UNK-and-UN-In-Date-Values/m-p/807227#M318211</guid>
      <dc:creator>klchtsk</dc:creator>
      <dc:date>2022-04-11T18:51:52Z</dc:date>
    </item>
  </channel>
</rss>

