BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Hi I have a question in my code;

 

I have date values in character format;

 

Exp:  Date   2015-09-25

 

I need to convert the date into 2015/09/25 which is in character format.

 

My code:

date1=input(date,yymmdd10.);
format date yymmdds10.;

 

But the code resulted in value numeric format. I need the value in chracter format. 2015/09/25. Please help.

 

Thank you

5 REPLIES 5
PGStats
Opal | Level 21

date = translate(date,"/","-");

PG
LinusH
Tourmaline | Level 20
Why do need it in char? Storing dates as numerical is much more flexible. There are tons of date functions available to you, and you could change the date format at blink of a second - no ned to rewrite to do conversion.
Data never sleeps
RW9
Diamond | Level 26 RW9
Diamond | Level 26

There is actually two instances where you might want character dates - ISO dates for instance are character.  The other is for display purposes, most times put to format is fine, but sometimes you may want additional information for report purposes.  

But I totally agree with you, unless there is a very good reason there is no reason to not use numeric date or time variables as they are far easier to use.  I suspect he is trying to put these in macro list or something similar (in which case don't).

jklaverstijn
Rhodochrosite | Level 12

You can use the inverse of INPUT, PUT:

 

date2=put(date1, yymmdds10.);

I refrain from disputing your expressed need for this. I think it is out of order until you have been asked questions on the matter, which has not happened. And I won't.

 

Hope this helps,

-Jan.

knveraraju91
Barite | Level 11

Hi all,,

 

Thank you very much. Both codes are working for me as I am validating a dataset using proc compare. Thank yoiu.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 2370 views
  • 2 likes
  • 5 in conversation