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.


 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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