Help using Base SAS procedures

Time Format

Occasional Contributor
Posts: 8

Time Format

Hey everyone,
Quick question. I searched online, but it seems SAS does not have a time format to omit the colon. I am in the middle of a program compiling a ton of logs; some are in 24 hour format, some are in 12 hour. The database I upload it to requires it be in HHMM - no colons, and exactly 4 characters.

I got it to 24 hour. Easy. 9:34am is now 9:34. However, I can't figure out how to get it to 0934. Any advice? Or should I use a PROC SQL statement?

Super Contributor
Super Contributor
Posts: 3,176

Re: Time Format

These two SAS time INFORMATs appear to behave inconsistently when tested (log below with results):

ND8601TM - handles "hhmm"
HHMMSS - expects seconds, so must use INPUT function and concatenate "00"

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:
time +informat +"hhmm"

Usage Note 11206: IS8601* FORMATS and INFORMATS for DATE, TIME, and DATETIME

21 data _null_;
22 tm = input('1212',ND8601TM.);
23 put tm= time.;
24 run;

NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

25 data _null_;
26 tm = input('1212' !! '00',hhmmss.);
27 put tm= time.;
28 run;

NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
Frequent Contributor
Posts: 102

Re: Time Format

Just make your own picture format.

proc format;
picture mysdt
low-high = '%0H%0M' (datatype = datetime);

data _null_;
myTime = hms(9,34,30);
format myTime mysdt.;
put myTime;
Occasional Contributor
Posts: 8

Re: Time Format

Posted in reply to CurtisMack
Thank you both! Curtis, that format picture worked perfectly!

I have another question now... I am trying to get the date in ISO 8601 format (YYYYMMDD). SAS calls this B8601DAw. as the output informat. However, there is no similar output format. The date in the worksheet is in MM/DD/YY format, and I have that properly selected, but SAS just errors out and says "NOTE: Invalid data for date in line 133 136-143." many times over throughout the file.

I'm sure this is a really simple solution... Does anybody have a recommendation for a good book for newbies? I'm sure I could get my company to buy one for me... I just need a good primer.

Valued Guide
Posts: 2,191

Re: Time Format

I think of informats being for input rather than output, so I find this posting a bit confusing.
For input use informat YYMMDD8. and for output read the doc for YYMMDDx. When x=N you get no delimiters.
Ask a Question
Discussion stats
  • 4 replies
  • 4 in conversation