First, the fact that you have a character DATE/TIME value (not a character DATE value) indicates that somewhere earlier in the process, things were not being done in an optimal fashion. Calendar and clock information should always be numeric, never character. You might want to address this in your code (if you have created the character variable) or address this with the providers of the data if possible.
You asked to convert to 'DATE' and not date/time, so this will work:
chardatetime='2023-02-16 03:06:32.9088697 -05:00';
format date yymmddd10.;
Which DATE do you want? The 16th as listed in the string? Or do you want the 15th after you subtract the 5 hours implied by the negative 5:00 at the end?
And what do you want to do with the time of day component of the string?
You will probably want to parse the string into its three components and read each separately.
input string $34.;
2023-02-16 03:06:32.9088697 -05:00
data want ;
date1 = input(scan(string,1,' '),yymmdd10.);
tod = input(scan(string,2,' '),time16.);
tzoffset = input(scan(string,3,' '),time6.);
datetime2=datetime1 + tzoffset;
format date: yymmdd10. tod tod16.7 tzoffset time10. datetime: datetime26.5;
1355 data _null_;
1356 set want;
1357 put (_all_) (=/);
string=2023-02-16 03:06:32.9088697 -05:00
NOTE: There were 1 observations read from the data set WORK.WANT.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.