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!
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?
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?
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!
Then accept it as a solution please. This will mark this thread as answered.
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!
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.