change symbol in formatted SAS Date from "/" to "-"

Experts,

How would I change the "/" in a SAS formatted date to "-"?

I would like to see   01-01-2014      instead of    01/01/2014
moriniaAdvanced Analytics AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

IanStatisticianCommented:
Hi there Morina,

The setting of a format type onto the variable may be what you want.  In either DATA steps and most PROC steps you can have something the following statement.
format invoiceDate DDMMYYD10.;

Open in new window

which will give the numeric variable "invoiceDate" the specified format so that a date of 17 March 2014 will print out as  17-03-2014  
The final "D" in the format string "DDMMYYD10." can be interpreted as "dash".  If you replace the D with P in that format string it will print with full stops (Periods) and C instead of D will print Colons.  Without a letter in that position it prints slashes.

The following is a small subset of the formats availoable
Format      Example
DDMMYY.     17/03/11  
DDMMYY10.   17/03/2011
MMDDYY.     03/17/11  
MMDDYY10.   03/17/2011

DDMMYYD.    17-03-11  
DDMMYYD10.  17-03-2011
MMDDYYD.    03-17-11  
MMDDYYD10.  03-17-2011

Open in new window


==============

However if you have the date in a character variable then I suggest you use "translate".

data  newDataset;
       set oldDataset;

/* in this case invoiceDate is a character variable */

       /* change all slash characters into dashes */
       invoiceDate = translate(invoiceDate, '-', '/');

run;

/* Now when printed the column invoiseDate will show  17-03-2014 instead of 17/03/2014 */

Open in new window


Regards,

Ian
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.