BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
goms
Fluorite | Level 6

Hi,

I want to look at the date value below

Please let me know how to change the date format as it has char type

source

19700101 01:00:00 

 

 

Target

1970-01-01 01:00:00

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

At least in SAS 9.2, the anydtdtm format coughed up with that string, so I resorted to:

data test;
char_var = '19700101 01:00:00';
date_var = dhms(
  input(substr(char_var,1,8),yymmdd8.),
  input(substr(char_var,10,2),2.),
  input(substr(char_var,13,2),2.),
  input(substr(char_var,16,2),2.)
);
format date_var e8601dt19.;
run;

The ISO 8601 format looks almost like that what the OP wanted.

View solution in original post

3 REPLIES 3
Reeza
Super User

You would typically use input but I'm not sure your date is in a format SAS will recognize. 

 

Date_var = input(char_var, anydtdtm.);

fomat date_var datetime21.;

 

If that doesn't work you'll have to separately input each portion, date and time, and then stitch them together again. 

Kurt_Bremser
Super User

At least in SAS 9.2, the anydtdtm format coughed up with that string, so I resorted to:

data test;
char_var = '19700101 01:00:00';
date_var = dhms(
  input(substr(char_var,1,8),yymmdd8.),
  input(substr(char_var,10,2),2.),
  input(substr(char_var,13,2),2.),
  input(substr(char_var,16,2),2.)
);
format date_var e8601dt19.;
run;

The ISO 8601 format looks almost like that what the OP wanted.

goms
Fluorite | Level 6

Thank u so much. its really helpful

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 1496 views
  • 1 like
  • 3 in conversation