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').
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.