BookmarkSubscribeRSS Feed
marleeakerson
Calcite | Level 5

Hello,

 

I am having some trouble changing my date variable to a usable format. I have been able to change it to the 8 digit, MMDDYYYY format, but once I try to put the parathesis in to make it DD/MM/YYYY the numbers completely change and everything gets messy. I have offered photos for reference. 

 

date1.PNGdate2.PNG

 

This is the only code I used for this:

 

data want;
set have;
format transaction_date MMDDYY10.;
run;

 

Thank you!

3 REPLIES 3
Reeza
Super User
Your first variable is a number, but not a SAS date. You first need to convert it to a SAS date and then apply the format.

transaction_date_sas = input(put(transaction_date, mmddyy10.), mmddyy10.);
format transaction_date ddmmyy10.;
Tom
Super User Tom
Super User

Looks like it is doing what you asked.  Consider this little program.

data test;
   input x;
   year=year(x);
   month=month(x);
   day=day(x);
   put (_all_) (= comma12.);
cards;
01082012
04112007
;
x=1,082,012 year=4,922 month=6 day=14
x=4,112,007 year=13,218 month=4 day=20

So one million days since 1960 is in the middle of the year 4922. 4 million days is after the start of the year 13,218!

 

First convert the value to an actual date (at least for the numbers that are valid dates).  Then you can use the value as a date and attach any date format you want to use when display the values.  Personally I avoid MMDDYY or DDMMYY format as whichever one you pick half of your audience will be confused.

fixed=input(put(transaction_date,Z8.),mmddyy8.);
format fixed yymmdd10.;

 

Kurt_Bremser
Super User

I'd also much rather use either YYMMDDD10. or E8601DA10. as a date format. This is the internationally standardized way to write dates and leaves no ambiguity.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 570 views
  • 0 likes
  • 4 in conversation