DATA Step, Macro, Functions and more

Correct date with swapped year and day values

Accepted Solution Solved
Reply
Super User
Super User
Posts: 6,502
Accepted Solution

Correct date with swapped year and day values

This question was recently posted on stackoverflow. 

 

I am working with a dataset containing a date variable with the format MMDDYY10.. The problem is, that the day, month and the year have been swapped.

The data set as it looks now:

Obs Date
1   11/01/1931
2   11/06/1930
3   12/02/2003
4   12/07/2018

What I would like is a date variable with the format DDMMYY10., or a similar:

Obs Date
1   31/01/2011
2   30/06/2011
3   03/02/2012
4   18/07/2012

Observation 1 is hence written as the 1st of November 1931, but really it is the 31st of January 2011.

Does anyone know how I can change this?


Accepted Solutions
Solution
‎09-25-2015 06:23 AM
Super User
Super User
Posts: 6,502

Re: Correct date with swapped year and day values

I am typing this on cell phone. I noticed that the code formatting did display in chrome browser on my cell phone.

View solution in original post


All Replies
Super User
Super User
Posts: 6,502

Re: Correct date with swapped year and day values

[ Edited ]
data have ;
  input olddate mmddyy10.;
  newdate = input(put(olddate,mmddyy6.),yymmdd6.);
  format olddate newdate yymmdd10. ;
  put (olddate newdate) (=);
cards;
11/01/1931
11/06/1930
12/02/2003
12/07/2018
;;;;
Solution
‎09-25-2015 06:23 AM
Super User
Super User
Posts: 6,502

Re: Correct date with swapped year and day values

I am typing this on cell phone. I noticed that the code formatting did display in chrome browser on my cell phone.
Super User
Super User
Posts: 6,502

Re: Correct date with swapped year and day values

It does not seem possible to edit replies on a cell phone.
☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 162 views
  • 0 likes
  • 1 in conversation