DATA Step, Macro, Functions and more

SAS Dates

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

SAS Dates

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!


Accepted Solutions
Solution
‎10-09-2015 11:17 AM
Trusted Advisor
Posts: 1,631

Re: SAS Dates

[ Edited ]

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?

View solution in original post


All Replies
Solution
‎10-09-2015 11:17 AM
Trusted Advisor
Posts: 1,631

Re: SAS Dates

[ Edited ]

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?

New Contributor
Posts: 2

Re: SAS Dates

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!

Respected Advisor
Posts: 3,908

Re: SAS Dates

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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