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

Hi all, 

 

I have below data:

Capture.PNG

 

And attributes are as below:

Capture 1.PNG

 

I would like to convert it to iso8601 character format. Could you please give me some idea how to convert this type of data into ISO 8601 character?

 

Thanks,

Adi

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Here's an example. As you can see, a numeric variable formatted with the ISO format and a character variable created using the same format both look the same. I consider it a best practice to always store dates as numeric variables and control the display with a FORMAT statement. Dates stored as character strings are rarely useful.

iso8601_convert_date.png

 

Hope this helps,

Cynthia

View solution in original post

8 REPLIES 8
ballardw
Super User

@chinna0369 wrote:

Hi all, 

 

I have below data:

Capture.PNG

 

And attributes are as below:

Capture 1.PNG

 

I would like to convert it to iso8601 character format. Could you please give me some idea how to convert this type of data into ISO 8601 character?

 

Thanks,

Adi


Which specific ISO format? SAS has about  20 different ISO format that could be used. Look in the documentation for B8601 and E8601 formats.

Since your current value is CHARACTER likely the first step would be to get a SAS date time value using the input function and then PUT the result into a character value using the appropriate format. Or create a datetime variable and just associate the desired format. Then if you want to display the value as something else you may only need to change a format and not modify the data set.

chinna0369
Pyrite | Level 9

Thank you for your reply!

 

Can you give me some example code by using b8601.

 

Thanks,

Adi

Cynthia_sas
SAS Super FREQ

Here's an example. As you can see, a numeric variable formatted with the ISO format and a character variable created using the same format both look the same. I consider it a best practice to always store dates as numeric variables and control the display with a FORMAT statement. Dates stored as character strings are rarely useful.

iso8601_convert_date.png

 

Hope this helps,

Cynthia

chinna0369
Pyrite | Level 9

Thank you so much Cynthia_sas

chinna0369
Pyrite | Level 9

Hi Cynthia,

 

Right now we are getting date as below:

 

Capture.PNG

 

what do I need to use if want to get as below?

 

Capture 1.PNG

 

 

Thanks,

Adi

 

 

 

Cynthia_sas
SAS Super FREQ

Hi:

  I'm not on a machine where I can do documentation right now. You can look in the list of formats for the right format to get the date the  way you want.

cynthia

ballardw
Super User

That looks like you may want the E8601DTw.d format but the shortest version of that is 19 characters and will show seconds.

If that is unacceptable you will have to create a custom format.

chinna0369
Pyrite | Level 9

Hi all, 

 

Thanks, I got it. I changed it to " E8601DTw.d" it looks fine to me. 

 

Thanks,

Adithya

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 6051 views
  • 2 likes
  • 3 in conversation