DATA Step, Macro, Functions and more

time HHMMSS format

Reply
Contributor
Posts: 58

time HHMMSS format


Hi,

I would show a time in the format HHMMSS where:

HH, MM, SS have always 2 digit, I means 9:1:1 in should be 090101.

I'ev trie time but its behaviour is different.

Do there is a format that works in that way?

Many thanks.

Regards.

Occasional Contributor
Posts: 14

Re: time HHMMSS format

Hi Garag,

Please check this


data _null_;

abc='09:01:12't;
res=compress(put(abc,time8.),':');
put res=;

run;


Frequent Contributor
Posts: 78

Re: time HHMMSS format

Posted in reply to NagendraKumarK

This is the way I've done it, but I was hoping there was a more direct way.  Frankly I'm surprised there isn't a built-in format for this.

Valued Guide
Posts: 2,177

Re: time HHMMSS format

there is that "more direct" way

try

%put %sysfunc( putn( '9:9:9't, B8601TM )) ;

I get

090909

SAS9.2 doc can be found at http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003169787.htm

Message was edited by: Peter Crawford showing how these formats can easily be found ---> Session ID: 1744 Session Title: VFORMAT Lets SAS® Do the Format Searching my short paper will be presented some time between 24th and 26th March 2014 in SAS Global Forum  www.sasglobalforum.org

Respected Advisor
Posts: 3,799

Re: time HHMMSS format

I thought that one of those 8601 formats might work but I could never find it.  I remembered your search technique, I think you showed us that on SAS-L in the not too distant past, but I was too lazy to follow through.  Glad to see that you will presenting it at SGF.  The SGF reviewers did not like my ideas this year or last, but they did say they hope I enjoy the conference. Right.

PROC Star
Posts: 7,474

Re: time HHMMSS format

Posted in reply to data_null__

DN:  The SGF reviewers obviously don't have a clear concept of what most of us want to see.  I haven't seen what may have been selected in the second go round but, from the initial listing, it was just the same old.  I've been waiting for years to see you present!

Respected Advisor
Posts: 3,799

Re: time HHMMSS format

You haven't missed anything, but I do like to hear myself talk. :smileyshocked:

Contributor
Posts: 58

Re: time HHMMSS format

The developers that have created SAS they never used SAS I think, because otherwise these developers, in the case they used the software they have been produced, they should choosen a name for the format more easy to find

Contributor
Posts: 58

Re: time HHMMSS format


Hi Peter,

I'm running 9.1 and I think that the format B8601TM is not available


data _null_;
  abc='9:9:2't;
  res=put(abc,B8601TM.);
  put res=;
  run;

ERROR 48-59: The format B8601TM was not found or could not be loaded.

Thanks

PROC Star
Posts: 7,474

Re: time HHMMSS format

: I can't recall whether it was or wasn't available in 9.1, but you might want to try it .. adding the desired length to the format.

As for the names, there are so many formats and informats, naming would be problematic for anyone.  In the case, the formats conform to the ISO 8601 standard, thus would make sense to some.

Valued Guide
Posts: 2,177

Re: time HHMMSS format

garag

why not upgrade from SAS9.1 It is so out-of-date

SAS don't charge any more when you upgrade your release (but I don't speak for SAS)

everything improves

you might have work to migrate a metadata server

but the effort is worth it

there are many more improvements than just this little  B8601TM format

Contributor
Posts: 58

Re: time HHMMSS format

Posted in reply to NagendraKumarK

Hi NagendraKumarK,

it does not work, I get

90112

but is would get always 2 digit for the hour, 2 for minutes, 2 for hours, I mean in this case I would get 090112

Thanks

Respected Advisor
Posts: 3,799

Re: time HHMMSS format

proc format;
  
picture todx other='%0H%0M%0s' (datatype=time);
   run;
Frequent Contributor
Posts: 106

Re: time HHMMSS format

Hi, Try this :

data _null_;

format time tod.; /*just to show difference*/

time='9:1:12't;

time6=compress(put(time,tod.),':');

put "time=" time;

put "time6=" time6;

run;

output:

time=09:01:12

time6=090112

Ask a Question
Discussion stats
  • 13 replies
  • 2174 views
  • 7 likes
  • 7 in conversation