BookmarkSubscribeRSS Feed
Hansmuffs
Fluorite | Level 6

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;

 

 

3 REPLIES 3
maguiremq
SAS Super FREQ
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;

maguiremq_0-1647428793821.png

Remove the FORMAT if you don't want it formatted.

Kurt_Bremser
Super User

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;
FreelanceReinh
Jade | Level 19

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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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 lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1317 views
  • 1 like
  • 4 in conversation