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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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