Announcement

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

  • How to convert a date string variable to an actual variable made of year?

    Hi can you please help me?

    I have a variable in state stored as string like this: " 2021-10-16" until 2022, and the days and month are not in order. I am trying to convert this variables to just 2021, 2022, by collapsing all these months/days into just year. Can you help me?

    Thank you so much.
    Dania
    Attached Files

  • #2
    Code:
    gen year= real(substr(trim(DATE), 1, 4)), after(DATE)

    Comment


    • #3
      Thank you so much for your help Andrew!! It worked! Thanks!

      Comment


      • #4
        Andrew Musau solved the problem. In addition, the evidence of your screenshot is that such string dates could be sorted into date order, so long as dates in January to September are represented by 01 to 09 not 1 to 9.

        Comment

        Working...
        X