?
Solved

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

Posted on 2014-08-13
1
Medium Priority
?
672 Views
Last Modified: 2016-02-13
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
0
Comment
Question by:morinia
1 Comment
 
LVL 8

Accepted Solution

by:
ShannonEE earned 1000 total points
ID: 40259706
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question