Hi,
this is my string 14.03.2022 08:00:50 Input is $20. How to convert this string to timestamp?
The code below give back empty field BEGINN.
data &wkLibname..F_DATA; format BEGINN_TMP DATETIME26.; set &wkLibname..DATA_RAW; BEGINN_TMP = input(BEGINN, NLDATM.); DROP BEGINN; RENAME BEGINN_TMP = BEGINN; run;
data have;
input beginn $20.;
datalines;
14.03.2022 08:00:50
;
run;
data want;
set have;
beginn_tmp = input(beginn, ANYDTDTM.);
format beginn_tmp datetime19.;
run;
Remove the FORMAT if you don't want it formatted.
I really do not like the vagaries of the "ANY" informats, so I force correct informats for the date and time part:
data have;
input beginn $20.;
datalines;
14.03.2022 08:00:50
;
data want;
set have (rename=(beginn=_beginn));
format beginn e8601dt19.;
beginn = dhms(
input(scan(_beginn,1," "),ddmmyy10.),
0,
0,
input(scan(_beginn,2," "),time8.)
);
drop _beginn;
run;
Hi @Hansmuffs,
Your code should work well if you are using the typical German setting of system option LOCALE, i.e.
options locale=DE_DE;
It also works with some other locales, e.g., FR_FR or EN_GB, but not with EN_US (which in turn works with '03.14.2022 08:00:50').
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.