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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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