<?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: help adding leading zero to timpart in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/help-adding-leading-zero-to-timpart/m-p/636039#M188890</link>
    <description>&lt;P&gt;Just use a display format that puts in the zero.&lt;/P&gt;
&lt;PRE&gt;195   data _null_;
196    x='08:00't;
197    put x= time8. / x=tod8. ;
198   run;

x=8:00:00
x=08:00:00
&lt;/PRE&gt;</description>
    <pubDate>Tue, 31 Mar 2020 00:36:13 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-03-31T00:36:13Z</dc:date>
    <item>
      <title>help adding leading zero to timpart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-adding-leading-zero-to-timpart/m-p/636036#M188888</link>
      <description>&lt;P&gt;I've tried various things but I'm not able to add a leading zero to timepart after converting it to character. If the timepart is 9:29:40 I want it to be 09:29:40. I thought using length would work but it turns out that even though nothing appears to be in the first slot, length still counts something as being there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data table1;
infile datalines;
input did pgm_id user $ dttime DATETIME24.3; 
format dttime DATETIME24.3;
return;
datalines;
8 63832680 DAN 23AUG2013:19:42:55.160
2 63832680 JAN 01AUG2013:19:20:58.785
6 63832680 DAN 22AUG2013:08:57:12.506
4 63832680 DAN 13AUG2013:19:29:39.578
7 63832680 DAN 23AUG2013:15:30:00.452
9 63832680 DAN 26AUG2013:07:29:40.386
1 63832680 BOB 14AUG2013:22:24:41.894
5 63832680 DAN 16AUG2013:00:40:52.547
3 63832680 DAN 08AUG2013:05:13:00.356
;
run;

data table2;
	set table1;
	format new_dt yymmdds10.;
	format new_tm time8.;
	format tm_new2 tm_new3  y $8.;
	new_dt=datepart(dttime);
	new_tm=timepart(dttime);
	dt_new1=PUT(new_dt, yymmdds10.);
	tm_new1=PUT(new_tm, time8.);
	var1= PUT(INPUT(new_tm, time8.), z8.);
	if length(tm_new1) = 7 then tm_new2= cat('0',tm_new1);
	else tm_new2=tm_new1;
	
	if length(tm_new1) = 7 then tm_new3= '0' || tm_new1;
	else tm_new3=tm_new1;
	len=length(tm_new1);
	y=translate(tm_new1,' ','&amp;amp;');
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Mar 2020 23:46:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-adding-leading-zero-to-timpart/m-p/636036#M188888</guid>
      <dc:creator>DanD999</dc:creator>
      <dc:date>2020-03-30T23:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: help adding leading zero to timpart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-adding-leading-zero-to-timpart/m-p/636038#M188889</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49285"&gt;@DanD999&lt;/a&gt;&amp;nbsp; Please see if this helps&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	tm_new1=translate(right(PUT(new_tm, time8.)),'0',' ');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Basically the idea is&lt;/P&gt;
&lt;P&gt;1. Move the formatted character value to the right, or in other &lt;SPAN&gt;w&lt;/SPAN&gt;ords, right align the formatted char value.&lt;/P&gt;
&lt;P&gt;2.Translate the leading blank(if exists)&amp;nbsp; &lt;SPAN&gt;w&lt;/SPAN&gt;ith 0&lt;/P&gt;
&lt;P&gt;Should be straight for&lt;SPAN&gt;ward to understand&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Mar 2020 00:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-adding-leading-zero-to-timpart/m-p/636038#M188889</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-31T00:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: help adding leading zero to timpart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-adding-leading-zero-to-timpart/m-p/636039#M188890</link>
      <description>&lt;P&gt;Just use a display format that puts in the zero.&lt;/P&gt;
&lt;PRE&gt;195   data _null_;
196    x='08:00't;
197    put x= time8. / x=tod8. ;
198   run;

x=8:00:00
x=08:00:00
&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Mar 2020 00:36:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-adding-leading-zero-to-timpart/m-p/636039#M188890</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-31T00:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: help adding leading zero to timpart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-adding-leading-zero-to-timpart/m-p/636112#M188919</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;PRE&gt;data table2;
	set table1;
	format new_dt yymmdds10.;
	format new_tm time8.;
	format tm_new2 tm_new3  y $8.;
	new_dt=datepart(dttime);
	new_tm=timepart(dttime);
	new_tm=time8. / new_tm=tod8. ;
run;
31         	new_tm=time8. / new_tm=tod8. ;
                   ______          _____
                   386             390
                   201             201
ERROR 386-185: Expecting an arithmetic expression&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Mar 2020 08:28:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-adding-leading-zero-to-timpart/m-p/636112#M188919</guid>
      <dc:creator>DanD999</dc:creator>
      <dc:date>2020-03-31T08:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: help adding leading zero to timpart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-adding-leading-zero-to-timpart/m-p/636128#M188927</link>
      <description>&lt;P&gt;Do not use formats in an attempt to tell SAS how to do calculations other than with INPUT functions creating numeric values from character as part of the calculation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is this supposed to do?&lt;/P&gt;
&lt;PRE&gt;new_tm=time8. / new_tm=tod8. ;&lt;/PRE&gt;
&lt;P&gt;SAS sees an attempt to assign a value to the variable new_tm with the "value" of time8. which is not a valid variable name or value. So the time8. is not a valid arithmetic expression and throws an error. The code goes on the attempt to divide that non-valid value by the result of comparing new_tm to the value tod8. causing another identical error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The current format of a date, time or datetime variable has no effect on how the value is used in calculations. None.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Mar 2020 09:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-adding-leading-zero-to-timpart/m-p/636128#M188927</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-31T09:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: help adding leading zero to timpart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-adding-leading-zero-to-timpart/m-p/636135#M188933</link>
      <description>&lt;P&gt;I wasn't trying to do a calculation originally. This was a solution someone provided. I'd never seen something like and couldn't get it to work. Thanks for the comment.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Mar 2020 09:58:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-adding-leading-zero-to-timpart/m-p/636135#M188933</guid>
      <dc:creator>DanD999</dc:creator>
      <dc:date>2020-03-31T09:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: help adding leading zero to timpart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-adding-leading-zero-to-timpart/m-p/636154#M188948</link>
      <description>&lt;P&gt;you missed to add PUT statement in&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_tm=time8. / new_tm=tod8. ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the syntax.&amp;nbsp; You could use TOD format instead of time8. format to get the same result&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;tm_new1=PUT(new_tm, tod8.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Mar 2020 10:34:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-adding-leading-zero-to-timpart/m-p/636154#M188948</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-31T10:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: help adding leading zero to timpart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-adding-leading-zero-to-timpart/m-p/636199#M188980</link>
      <description />
      <pubDate>Tue, 31 Mar 2020 12:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-adding-leading-zero-to-timpart/m-p/636199#M188980</guid>
      <dc:creator>DanD999</dc:creator>
      <dc:date>2020-03-31T12:19:31Z</dc:date>
    </item>
  </channel>
</rss>

