<?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: prxchange-adding digits after buffer in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/prxchange-adding-digits-after-buffer/m-p/644012#M192299</link>
    <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 29 Apr 2020 16:10:27 GMT</pubDate>
    <dc:creator>Caetreviop543</dc:creator>
    <dc:date>2020-04-29T16:10:27Z</dc:date>
    <item>
      <title>prxchange-adding digits after buffer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxchange-adding-digits-after-buffer/m-p/643997#M192289</link>
      <description>&lt;P&gt;I'm trying to modify a timestamp variable (currently in character form) to include zeros in the milliseconds column:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Timestamp 
2010-12-07 10:20:00
2011-12-10 13:21:54
2011-10-09 08:10:45.333
2011-08-15 10:15:33.4
2009-07-27 11:26:24.56
2009-10-10 14:13:00&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I need to add zeros to the milliseconds column, to look like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Timestamp
2010-12-07 10:20:00.000
2011-12-10 13:21:54.000
2011-10-09 08:10:45.333
2011-08-15 10:15:33.400
2009-07-27 11:26:24.560
2009-10-10 14:13:00.000&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried using prxchange:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
 *timestamps with just seconds;
timestamp_new=prxchange('s/(:\d\d)  /$1.000/', -1, timestamp);
*timestamp with one digit in milliseconds;
timestamp_new=prxchange('s/(\.\d)  /$100/', -1, timestamp_new);


run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The first prxchange for records with just seconds using the capture buffer works. However, the second prxchange not only doesn't add 00 milliseconds but deletes seconds. It seems to be an issue with the fact that I want the digits 00 to come right after the capture buffer. Putting a space between the capture buffer and 00 produces expected results.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There may also be an easier way to add zeros to the milliseconds column.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 15:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxchange-adding-digits-after-buffer/m-p/643997#M192289</guid>
      <dc:creator>Caetreviop543</dc:creator>
      <dc:date>2020-04-29T15:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: prxchange-adding digits after buffer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxchange-adding-digits-after-buffer/m-p/644005#M192294</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/86015"&gt;@Caetreviop543&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/86015"&gt;@Caetreviop543&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;There may also be an easier way to add zeros to the milliseconds column.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Perhaps something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
timestamp=translate(put(input(timestamp,e8601dt23.),e8601dt23.3),' ','T');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(If you really don't want to have a &lt;EM&gt;numeric&lt;/EM&gt; timestamp with a datetime format.)&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 15:47:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxchange-adding-digits-after-buffer/m-p/644005#M192294</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-04-29T15:47:39Z</dc:date>
    </item>
    <item>
      <title>Re: prxchange-adding digits after buffer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxchange-adding-digits-after-buffer/m-p/644007#M192296</link>
      <description>&lt;P&gt;Thanks, that worked. I actually want to change it to numeric. Would the code instead look like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #000000; font-family: Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 24px; -ms-hyphens: none; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-shadow: 0px 1px white; text-transform: none; -webkit-text-stroke-width: 0px; white-space: pre; word-break: normal; word-spacing: 0px; word-wrap: normal;"&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;timestamp=translate(input(timestamp,e8601dt23.),' ','T');&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 15:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxchange-adding-digits-after-buffer/m-p/644007#M192296</guid>
      <dc:creator>Caetreviop543</dc:creator>
      <dc:date>2020-04-29T15:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: prxchange-adding digits after buffer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxchange-adding-digits-after-buffer/m-p/644010#M192297</link>
      <description>&lt;P&gt;The character function TRANSLATE cannot be applied to a numeric argument. You need a new variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=timestamp rename=(timestampn=timestamp));
set have;
timestampn=input(timestamp,e8601dt23.);
format timestampn e8601dt23.3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the "T" in the ISO 8601 format is a problem, you may want to create a user-defined (picture) format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
picture dspacet
other='%0Y-%0m-%0d %0H:%0M:%0s' (datatype=datetime);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use this instead of e8601dt23.3 in the FORMAT statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format timestampn dspacet23.3;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Apr 2020 16:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxchange-adding-digits-after-buffer/m-p/644010#M192297</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-04-29T16:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: prxchange-adding digits after buffer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxchange-adding-digits-after-buffer/m-p/644012#M192299</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 16:10:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxchange-adding-digits-after-buffer/m-p/644012#M192299</guid>
      <dc:creator>Caetreviop543</dc:creator>
      <dc:date>2020-04-29T16:10:27Z</dc:date>
    </item>
  </channel>
</rss>

