- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have two columns like below, STDTC and ENDTC in string format ($100). I want to calculate the time difference between them. I tried to convert stdtc to datetime format but failed bacause only one row with time and other rows are date. Seems it cannot make this column to be both date and datetime. How to calculte ?
STDTC ENDTC
2022-01-03 2022-01-03
2022-03-22 2022-05-02
2022-06-02T10:30 2022-06-04
Thanks for your help!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You have to create new numeric variables from the character variables in order to work with these.
You show five dates, and one date/time ... exactly what result do you want here anyway?
Maybe this?
data have;
input STDTC $16. ENDTC :$16.;
cards;
2022-01-03 2022-01-03
2022-03-22 2022-05-02
2022-06-02T10:30 2022-06-04
;
data want;
set have;
stdtn=input(stdtc,B8601DT.);
endtn=input(endtc,B8601DT.);
delta=endtn-stdtn;
format delta time16.;
run;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You have to create new numeric variables from the character variables in order to work with these.
You show five dates, and one date/time ... exactly what result do you want here anyway?
Maybe this?
data have;
input STDTC $16. ENDTC :$16.;
cards;
2022-01-03 2022-01-03
2022-03-22 2022-05-02
2022-06-02T10:30 2022-06-04
;
data want;
set have;
stdtn=input(stdtc,B8601DT.);
endtn=input(endtc,B8601DT.);
delta=endtn-stdtn;
format delta time16.;
run;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The SAS help shows that B8601DT. writes datetime values in the ISO 8601 basic notation yyyymmddThhmmssffffff. , while E8601DT. in extended notation yyyy-mm-ddThh:mm:ss.ffffff.
Why E8601DT. reports the note ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This isn't a very good answer ... but B8601DT seems happy when the value is just a date and no time component, while E8601DT seems to only work when there is a time component. However, I don't see where the documentation says that.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@PaigeMiller wrote:
This isn't a very good answer ... but B8601DT seems happy when the value is just a date and no time component, while E8601DT seems to only work when there is a time component. However, I don't see where the documentation says that.
The difference in the documentation is that B8601dt includes:
If the hour, minute, or second values are omitted, SAS uses a value of 0 for the hour, minute, or second.
but E8601dt does not have a similar piece in the description.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@ballardw wrote:
@PaigeMiller wrote:
This isn't a very good answer ... but B8601DT seems happy when the value is just a date and no time component, while E8601DT seems to only work when there is a time component. However, I don't see where the documentation says that.
The difference in the documentation is that B8601dt includes:
If the hour, minute, or second values are omitted, SAS uses a value of 0 for the hour, minute, or second.but E8601dt does not have a similar piece in the description.
That answers the question!!
Paige Miller