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

Posted on 2014-08-13
Last Modified: 2016-02-13

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

I would like to see   01-01-2014      instead of    01/01/2014
Question by:morinia
    1 Comment
    LVL 8

    Accepted Solution

    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, '-', '/');
    /* Now when printed the column invoiseDate will show  17-03-2014 instead of 17/03/2014 */

    Open in new window



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Introduction: Often, when running a query with joins, the results show up "duplicates", and often, those duplicates can be "eliminated" in the results using DISTINCT, for example. Using DISTINCT is simple: just add it after the SELECT keyword, an…
    Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now