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

Hello!

 

I'm trying to convert a numeric sas variable (length 8, format yymmdd10.) to date9. format. Currently the dates look like 2004-07-14 and I would like them to look like 14JUL2004. I've tried converting to character and then back to numeric but I must be doing something wrong. Can someone write out the code for how I make this change?

 

Thanks so much in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

SAS dates are internally represented by a number, representing the number of days since Jan 1, 1960. It is best to leave this internal representation and use formats to change how the number appear. There is no need to convert to character along the way.

 

So if you use format date9., you should see the date appear as you want. For example, in a data step, or in a PROC, use

format variablename date9.;

 

But beyond that, it's not clear what the problem is that you are facing. Can you show us the SAS code you are using?

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

SAS dates are internally represented by a number, representing the number of days since Jan 1, 1960. It is best to leave this internal representation and use formats to change how the number appear. There is no need to convert to character along the way.

 

So if you use format date9., you should see the date appear as you want. For example, in a data step, or in a PROC, use

format variablename date9.;

 

But beyond that, it's not clear what the problem is that you are facing. Can you show us the SAS code you are using?

--
Paige Miller
sweetpeaindeed2
Calcite | Level 5

It's not clear what the problem is because the solution is as easy as you were indicating. I was complicating the situation thinking I needed to transform the variable when you are right, all I needed to do was include the format statement.

 

Thanks for helping me discover my mistake!

Patrick
Opal | Level 21

Then accept it as a solution please. This will mark this thread as answered.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1319 views
  • 0 likes
  • 3 in conversation