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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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