- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have sas date time19. and want to extract hour minutes and seconds, I can use hour() function but if it is 00 then it wont work
date
15NOV2022:00:00:00
hour minute second
00 00 00
Can anyone help me in this
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@vraj1 wrote:
Yes, but if hour is missing it only give "0" but i need "00"
Zero is not a missing value. If the HOUR was missing then the whole datetime value would have had to have been missing.
If you have the value zero there is no difference between typing it as 0 or 00 or 0000 they all mean zero.
If you want to have a number printed using leading zeros then use the Z format.
Try this:
data want;
set have;
time=timepart(dtvar);
hour=hour(dtvar);
minute=minute(dtvar);
second=second(dtvar);
format time tod8. hour minute second z2. ;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes. The Functions Hour, Minute and Second all support datetime values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes, but if hour is missing it only give "0" but i need "00"
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@vraj1 wrote:
Yes, but if hour is missing it only give "0" but i need "00"
In SAS, a numeric variable can have a value of 0 but it cannot have a value of 00
If you really need a value of 00, assign a custom format to it.
This of course brings up the question, why do you need 00? Are you going to use it as a character string? Please explain this, as there are probably better ways to handle this.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why do you need 00 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@vraj1 wrote:
Yes, but if hour is missing it only give "0" but i need "00"
Zero is not a missing value. If the HOUR was missing then the whole datetime value would have had to have been missing.
If you have the value zero there is no difference between typing it as 0 or 00 or 0000 they all mean zero.
If you want to have a number printed using leading zeros then use the Z format.
Try this:
data want;
set have;
time=timepart(dtvar);
hour=hour(dtvar);
minute=minute(dtvar);
second=second(dtvar);
format time tod8. hour minute second z2. ;
run;