DATA Step, Macro, Functions and more

How to format MMDDYYYY10. to another date format?

Accepted Solution Solved
Reply
Super Contributor
Posts: 297
Accepted Solution

How to format MMDDYYYY10. to another date format?

Hello:

 

I would like to change the SAS format 09/15/2009 to 9/15/2009, or 08/06/2005 to 8/6/2005.    Please let me know how.  Thanks.

 

 


Accepted Solutions
Solution
‎06-12-2017 02:21 PM
Super User
Posts: 10,526

Re: How to format MMDDYYYY10. to another date format?

If you want a format permanently associated with a variable you have to use a FORMAT statement in a data step or modify in proc datasets.

 The code I provided was just to demostrate that when you use the sddate format that the appearance is as you requested.

It is up to you to attach or use the format when needed.

 

data test;

  d ='6Aug2005'd;

  put d sddate.;

  format d sddate.; 

run;

View solution in original post


All Replies
Super User
Posts: 10,526

Re: How to format MMDDYYYY10. to another date format?

Are you willing to create and use a custom date format? The behavior you request isn't supported by the SAS supplied formats.

proc format library=work;
picture sddate 
low-high = '%m/%d/%Y' (datatype=date);
run;

data _null_;
  d ='6Aug2005'd;
  put d sddate.;
run;
Super Contributor
Posts: 297

Re: How to format MMDDYYYY10. to another date format?

Yes.

 

Super Contributor
Posts: 297

Re: How to format MMDDYYYY10. to another date format?

The code I copied from you didn't show the result I would like to.

 

proc format library=work;

picture sddate

low-high = '%m/%d/%Y' (datatype=date);

run;

data test;

d ='05/06/2005'd;

put d sddate.;

run;

Super User
Posts: 10,526

Re: How to format MMDDYYYY10. to another date format?

[ Edited ]

ybz12003 wrote:

The code I copied from you didn't show the result I would like to.

 

proc format library=work;

picture sddate

low-high = '%m/%d/%Y' (datatype=date);

run;

data test;

d ='05/06/2005'd;

put d sddate.;

run;


Date literals must be of DATE7 or DATE9. such as 6MAY2005. Because there are so many different date formats in use only one is valid. For some folks the data you posted would be 5June2005, and for those that do not use a separator such as 201210 that could be: 20 Dec 2010, or October 2012. So you have to use the 3-letter month abbreviation and have day, Month, year

 

And the code you ran was not a copy of what I provided.

Super Contributor
Posts: 297

Re: How to format MMDDYYYY10. to another date format?

I got 'd' value for 16654.  However, I would like the format is 8/6/2005

Super User
Posts: 10,526

Re: How to format MMDDYYYY10. to another date format?

 


ybz12003 wrote:

I got 'd' value for 16654.  However, I would like the format is 8/6/2005


SAS date values are stored as a number of days from a base date of 1 Jan 1960.

That value has no format applied so uses the best. format to display a numeric value.

 

Show your work!

Please see the log when running this code.

data junk;

x = '06AUG2005'd;

put 'As integer ' x= best10.;

put 'date9 format ' x= date9.;

put 'mmddyy10 format ' x= mmddyy10.;

put 'sddate format ' x= sddate.;

run;

 

Super Contributor
Posts: 297

Re: How to format MMDDYYYY10. to another date format?

[ Edited ]

Yes, on the log is shown that:

 

15 data test;

16 d ='6Aug2005'd;

17 put d sddate.;

18 run;

8/6/2005

NOTE: The data set WORK.TEST has 1 observations and 1 variables.

NOTE: DATA statement used (Total process time):

real time 0.01 seconds

cpu time 0.00 seconds

 

However, when I open the test data set.  It shows:

 

The SAS System

 

Obs d 1
16654
Solution
‎06-12-2017 02:21 PM
Super User
Posts: 10,526

Re: How to format MMDDYYYY10. to another date format?

If you want a format permanently associated with a variable you have to use a FORMAT statement in a data step or modify in proc datasets.

 The code I provided was just to demostrate that when you use the sddate format that the appearance is as you requested.

It is up to you to attach or use the format when needed.

 

data test;

  d ='6Aug2005'd;

  put d sddate.;

  format d sddate.; 

run;

Super Contributor
Posts: 297

Re: How to format MMDDYYYY10. to another date format?

Thanks.  It works. Smiley Happy

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 151 views
  • 3 likes
  • 2 in conversation