BookmarkSubscribeRSS Feed
Russell
Calcite | Level 5
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?

Thanks!
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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" site:sas.com

Usage Note 11206: IS8601* FORMATS and INFORMATS for DATE, TIME, and DATETIME
http://support.sas.com/kb/11/206.html



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

tm=12:12:00
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;

tm=12:12:00
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
CurtisMack
Fluorite | Level 6
Just make your own picture format.

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

data _null_;
myTime = hms(9,34,30);
format myTime mysdt.;
put myTime;
run;
Russell
Calcite | Level 5
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.

Thanks!
Peter_C
Rhodochrosite | Level 12
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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 3659 views
  • 0 likes
  • 4 in conversation