<?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: Picture format for negative time duration in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Picture-format-for-negative-time-duration/m-p/754004#M237705</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;thank you all for your posts that led to this powerful demonstration.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think for now a single line data step check is the easiest solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But wow, I'm astonished by the combination of fcmp with the format, never thought of that.&lt;/P&gt;
&lt;P&gt;One is able to logically adjust the format on the fly, it's amazing.&lt;/P&gt;
&lt;P&gt;I'll definitely use it in the future and optimize some processes&lt;/P&gt;
&lt;P&gt;Thank you very much&lt;/P&gt;</description>
    <pubDate>Wed, 14 Jul 2021 08:02:11 GMT</pubDate>
    <dc:creator>Oligolas</dc:creator>
    <dc:date>2021-07-14T08:02:11Z</dc:date>
    <item>
      <title>Picture format for negative time duration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Picture-format-for-negative-time-duration/m-p/753605#M237549</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I'm wondering if you could please help with a custom time format that could represent negative durations (end before start)&lt;/P&gt;
&lt;P&gt;That's what I've got, Time5. works but not my picture format&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
   Bloodsample='2020-01-12T15:00'; Infusion='2020-01-12T15:10';output;
   Bloodsample='2019-11-18T14:40'; Infusion='2019-11-18T10:30';output;
   Bloodsample='2019-11-13T15:13'; Infusion='2019-11-18';output;
RUN;

PROC FORMAT;
   picture mytime 
      low - &amp;lt; 0 ='%Hh %0Mmn' (datatype=time prefix='-')
      0 - high='%Hh %0Mmn' (datatype=time)
      ;
run;

DATA want;
   set have;
   if length(Bloodsample) eq 16 and length(Infusion) eq 16 then do;
       dur=input(Infusion,b8601DT.) - input(Bloodsample,b8601DT.); 
       time5=put(dur,time5.);
       picture=put(dur,mytime.); *ERROR for Infusion &amp;lt; Bloodsample;
   end;
RUN;
PROC PRINT;RUN;&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, 12 Jul 2021 20:10:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Picture-format-for-negative-time-duration/m-p/753605#M237549</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2021-07-12T20:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: Picture format for negative time duration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Picture-format-for-negative-time-duration/m-p/753610#M237552</link>
      <description>&lt;P&gt;&lt;STRIKE&gt;Works fine for me, except for the last record but that's because you have data quality issues - a datetime with no time component.&lt;/STRIKE&gt;&lt;BR /&gt;&lt;STRIKE&gt;Please clarify what isn't working in detail.&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;I'm wrong, your code does have an issue.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 20:45:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Picture-format-for-negative-time-duration/m-p/753610#M237552</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-07-12T20:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: Picture format for negative time duration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Picture-format-for-negative-time-duration/m-p/753612#M237553</link>
      <description>&lt;P&gt;This works to put the minus sign.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;'-%Hh %0Mmn'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is this what what you wanted?&amp;nbsp; Because TIME5 is way different.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 66px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/61148i2A542CB59EE687DD/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 20:32:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Picture-format-for-negative-time-duration/m-p/753612#M237553</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2021-07-12T20:32:31Z</dc:date>
    </item>
    <item>
      <title>Re: Picture format for negative time duration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Picture-format-for-negative-time-duration/m-p/753614#M237555</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/77163"&gt;@Oligolas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I'm wondering if you could please help with a custom time format that could represent negative durations (end before start)&lt;/P&gt;
&lt;P&gt;That's what I've got, Time5. works but not my picture format&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
   Bloodsample='2020-01-12T15:00'; Infusion='2020-01-12T15:10';output;
   Bloodsample='2019-11-18T14:40'; Infusion='2019-11-18T10:30';output;
   Bloodsample='2019-11-13T15:13'; Infusion='2019-11-18';output;
RUN;

PROC FORMAT;
   picture mytime 
      low - &amp;lt; 0 ='%Hh %0Mmn' (datatype=time prefix='-')
      0 - high='%Hh %0Mmn' (datatype=time)
      ;
run;

DATA want;
   set have;
   if length(Bloodsample) eq 16 and length(Infusion) eq 16 then do;
       dur=input(Infusion,b8601DT.) - input(Bloodsample,b8601DT.); 
       time5=put(dur,time5.);
       picture=put(dur,mytime.); *ERROR for Infusion &amp;lt; Bloodsample;
   end;
RUN;
PROC PRINT;RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;The %H directive is the HOUR of the 24-hour clock time, not an interval. So for your second value which is showing "19h 50mn" that is 4 hours and 10 minutes BEFORE the end of the 24-hour clock. Just like %m shows the month number, not the interval from a previous date. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't get a result for the third row because you show an invalid datetime value (no time component)&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 12 Jul 2021 20:41:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Picture-format-for-negative-time-duration/m-p/753614#M237555</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-12T20:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: Picture format for negative time duration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Picture-format-for-negative-time-duration/m-p/753672#M237580</link>
      <description>&lt;P&gt;Hi, thanks the 3rd row is fine, sorry for the ambiguity. My problem is the 2nd row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;So, do you mean minus signs are not allowed because the %H directive is showing hours?&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;indeed with&amp;nbsp;'-%Hh %0Mmn' I get a minus sign output " -19h 50mn" with datatype=datetime,&lt;/P&gt;
&lt;P&gt;but I'd like to modify the picture format to get "-4h 10mn" in the 2nd row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in a datastep I would fix it with&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC FORMAT;
   picture mytime 
      low - high ='%Hh %0Mmn' (datatype=time);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;want=cats(ifc(dur&amp;lt;0,'-',''),put(abs(dur),mytime.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But how can I do this with the picture format?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 07:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Picture-format-for-negative-time-duration/m-p/753672#M237580</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2021-07-13T07:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Picture format for negative time duration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Picture-format-for-negative-time-duration/m-p/753767#M237622</link>
      <description>&lt;P&gt;It looks like PICTURE don't take negative value as a valid time value .&lt;/P&gt;
&lt;P&gt;And I am also surprised , if you use HOUR(-15000) ,MINUTE(-15000) would get different result from TIME5. format.&lt;/P&gt;
&lt;P&gt;I suggest you feedback to sas support.&lt;/P&gt;
&lt;P&gt;Here is a workaround way if you like it .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
   Bloodsample='2020-01-12T15:00'; Infusion='2020-01-12T15:10';output;
   Bloodsample='2019-11-18T14:40'; Infusion='2019-11-18T10:30';output;
   Bloodsample='2019-11-13T15:13'; Infusion='2019-11-18';output;
RUN;


proc fcmp outlib=work.math.func;
function mytime(x) $;
length mytime $ 10;
 if not missing(x)then mytime=cat(int(x/3600),'h ',put(abs(mod(x,3600)/60),z2.),'mn');
 return (mytime);
endsub;
run;

options cmplib=work.math;
PROC FORMAT;
   value mytime 
      low - high=[mytime()]
      ;
run;

DATA want;
   set have;
   if length(Bloodsample) eq 16 and length(Infusion) eq 16 then do;
       dur=input(Infusion,b8601DT.) - input(Bloodsample,b8601DT.); 
       time5=put(dur,time5.);
       picture=put(dur,mytime8.); *ERROR for Infusion &amp;lt; Bloodsample;
   end;
RUN;
PROC PRINT;RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Jul 2021 13:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Picture-format-for-negative-time-duration/m-p/753767#M237622</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-07-13T13:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: Picture format for negative time duration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Picture-format-for-negative-time-duration/m-p/753778#M237628</link>
      <description>&lt;P&gt;You can't do it with PICTURE because 3 hours before midnight is hour 21 not hour -3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to create your own function to produce the strings you want using PROC FCMP and call that function in the format definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or just make your original data step check the sign of the difference and then you can use your picture format on the absolute value of the difference.&amp;nbsp; So something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;picture=put(abs(dur),mytime.);
if . &amp;lt; dur &amp;lt;0 then picture=cats('-',picture);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Jul 2021 14:16:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Picture-format-for-negative-time-duration/m-p/753778#M237628</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-13T14:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Picture format for negative time duration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Picture-format-for-negative-time-duration/m-p/754004#M237705</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;thank you all for your posts that led to this powerful demonstration.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think for now a single line data step check is the easiest solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But wow, I'm astonished by the combination of fcmp with the format, never thought of that.&lt;/P&gt;
&lt;P&gt;One is able to logically adjust the format on the fly, it's amazing.&lt;/P&gt;
&lt;P&gt;I'll definitely use it in the future and optimize some processes&lt;/P&gt;
&lt;P&gt;Thank you very much&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 08:02:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Picture-format-for-negative-time-duration/m-p/754004#M237705</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2021-07-14T08:02:11Z</dc:date>
    </item>
  </channel>
</rss>

