Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Correcting dates

    I have a variable test_date which I have put into %td, which is a list of dates (DD/MM/YYYY).

    There are some errors in the data in that for some of the dates the years are not 2020 (i.e. all the dates included in the analysis should be in 2020). How do I code to make all the dates that are not based in 2020 (i.e. 23/02/1967) to be changed into 2020 (i.e. 23/02/1967 is changed into 23/02/2020)?

  • #2
    Code:
    replace date = mdy(month(date), day(date), 2020) if year(date) != 2020

    Comment


    • #3
      Originally posted by Nick Cox View Post
      Code:
      replace date = mdy(month(date), day(date), 2020) if year(date) != 2020
      Thank you very much Nick!

      Comment


      • #4
        Originally posted by Nick Cox View Post
        Code:
        replace date = mdy(month(date), day(date), 2020) if year(date) != 2020
        Sorry Nick, just for my reference, if I wanted to make these dates that were not in 2020 set as missing, how would I adjust the code to demonstrate this?

        Comment


        • #5
          Code:
          replace date = . if year(date) != 2020

          Comment

          Working...
          X