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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 739 views
  • 1 like
  • 4 in conversation