<?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: Add leading zeros to time variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-leading-zeros-to-time-variable/m-p/455400#M115191</link>
    <description>&lt;P&gt;Thanks Reeza, It worked.&lt;/P&gt;</description>
    <pubDate>Wed, 18 Apr 2018 20:55:47 GMT</pubDate>
    <dc:creator>Rupa</dc:creator>
    <dc:date>2018-04-18T20:55:47Z</dc:date>
    <item>
      <title>Add leading zeros to time variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-leading-zeros-to-time-variable/m-p/455397#M115188</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a time variable with the data as 03:45,1:25 etc with the length=15 and Char type. Can TOD5. be used for this time variable to add a leading zero which will make 1:25 as 01:25?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Details;&lt;/P&gt;&lt;P&gt;attrib TIME_&amp;nbsp; length=$15 tod5.;&lt;/P&gt;&lt;P&gt;if TIME= ' ' then;&lt;/P&gt;&lt;P&gt;TIME_= put(TIME, tod5.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above code is used,however does not change the values. Any suggestions would be of great help.&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rupa&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 20:37:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-leading-zeros-to-time-variable/m-p/455397#M115188</guid>
      <dc:creator>Rupa</dc:creator>
      <dc:date>2018-04-18T20:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: Add leading zeros to time variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-leading-zeros-to-time-variable/m-p/455399#M115190</link>
      <description>&lt;P&gt;Yes, you can, but you need to use INPUT to convert a character variable to a numeric variable. You also need to apply the format otherwise it's a number - the number of seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*create sample data;
data have;
input time_char $;
cards;
03:45
1:25
;;;;
run;


data want; 
set have;
*convert to a numeric SAS time;
time_num = input(time_char, time.);
*format with format desired;
format time_num tod5.;
run;

*Print results to test;
proc print data=want;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/205547"&gt;@Rupa&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a time variable with the data as 03:45,1:25 etc with the length=15 and Char type. Can TOD5. be used for this time variable to add a leading zero which will make 1:25 as 01:25?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data Details;&lt;/P&gt;
&lt;P&gt;attrib TIME_&amp;nbsp; length=$15 tod5.;&lt;/P&gt;
&lt;P&gt;if TIME= ' ' then;&lt;/P&gt;
&lt;P&gt;TIME_= put(TIME, tod5.);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above code is used,however does not change the values. Any suggestions would be of great help.&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Rupa&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 20:48:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-leading-zeros-to-time-variable/m-p/455399#M115190</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-18T20:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: Add leading zeros to time variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-leading-zeros-to-time-variable/m-p/455400#M115191</link>
      <description>&lt;P&gt;Thanks Reeza, It worked.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 20:55:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-leading-zeros-to-time-variable/m-p/455400#M115191</guid>
      <dc:creator>Rupa</dc:creator>
      <dc:date>2018-04-18T20:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: Add leading zeros to time variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-leading-zeros-to-time-variable/m-p/455404#M115192</link>
      <description>&lt;P&gt;This code doesn't make much sense.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Details;
  attrib TIME_  length=$15 tod5.;
  if TIME= ' ' then;
  TIME_= put(TIME, tod5.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The $ in the value of the LENGTH means you are defining a character variable. You can't attach a numeric format like TOD to a character variable.&amp;nbsp;&amp;nbsp;The IF statement doesn't make any sense because there is not statement to execute when the condition is true.&amp;nbsp; Perhaps you didn't mean to include the semi-colon ? Also you are not reading any data in this code.&amp;nbsp; Needs a SET or INPUT statement. Or at least an assignment statement to give TIME some value(s).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a character variable now and what to keep it as character you could read the text into a time value and then write it back out using the TOD format?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if not missing(time) then time=put(input(time,time5.),tod5.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or if the issue is just that some values have 4 characters when the first value is less than 10 you could just add the zero.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if 4=length(time) then time='0'||time;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Apr 2018 21:19:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-leading-zeros-to-time-variable/m-p/455404#M115192</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-18T21:19:28Z</dc:date>
    </item>
    <item>
      <title>Re: Add leading zeros to time variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-leading-zeros-to-time-variable/m-p/456547#M115652</link>
      <description>&lt;P&gt;Thanks Tom&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 14:41:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-leading-zeros-to-time-variable/m-p/456547#M115652</guid>
      <dc:creator>Rupa</dc:creator>
      <dc:date>2018-04-23T14:41:39Z</dc:date>
    </item>
  </channel>
</rss>

