BookmarkSubscribeRSS Feed
Eugenio211
Quartz | Level 8

Hello, 

 

how can we translate a character into date format,

 

here is an example of my data: 2022-01-01 04:12:30.9808034 -05:00

 

thank you.

2 REPLIES 2
ballardw
Super User

If you truly only need the date portion this is probably easiest:

 

data example;
   x= "2022-01-01 04:12:30.9808034 -05:00";
   y= input(x,yymmdd10.);
   format y yymmdd10.;
run;

If you need the time and time zone info you need to get used to dealing with SAS terminology of date, time and datetime as DATE values use different units, days, than time and datetime values which use seconds.

 

https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.

Reeza
Super User

Not being pedantic, but this is a datetime, not a date and SAS treats them differently. 

 

A date is stored as the number of days from January 1, 1960.

A datetime is stored as the number of seconds from January 1, 1960.

 

Do you want a date or datetime read in?

 

Here's a great, but longer and in depth, reference for dates and times in SAS
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/...

 


@Eugenio211 wrote:

Hello, 

 

how can we translate a character into date format,

 

here is an example of my data: 2022-01-01 04:12:30.9808034 -05:00

 

thank you.


 

 

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
  • 2 replies
  • 349 views
  • 0 likes
  • 3 in conversation