BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

9 REPLIES 9
ballardw
Super User

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;
ybz12003
Rhodochrosite | Level 12

Yes.

 

ybz12003
Rhodochrosite | Level 12

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;

ballardw
Super User

@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.

ybz12003
Rhodochrosite | Level 12

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

ballardw
Super User

 


@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;

 

ybz12003
Rhodochrosite | Level 12

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
ballardw
Super User

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;

ybz12003
Rhodochrosite | Level 12

Thanks.  It works. 🙂

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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