Announcement

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

  • String Date Variable with Two "Formats" of Date

    Hi all,

    Code:
    input str10 expectCompleteDt
    ""               
    "1/1/2014"
    "1/1/2022"
    "1/1/2022"
    "1/1/2022"
    "16252"
    I would like to have this variable, which is string but represents a daily date, contain dates only as the number of days since 1st of January 1960 (i.e. following the format 16252 already in the dataset). So the format MM/DD/YYYY must be changed, and instead reflect the number of days since 1st of January 1960.

    How could I do this?

    Many thanks in advance!





  • #2
    Code:
    clear all
    input str10 src
    ""               
    "1/1/2014"
    "1/1/2022"
    "1/1/2022"
    "1/1/2022"
    "16252"
    end
    
    generate int target=real(src)
    replace target=date(src,"MDY") if missing(target)
    
    list


    Code:
         +-------------------+
         |      src   target |
         |-------------------|
      1. |                 . |
      2. | 1/1/2014    19724 |
      3. | 1/1/2022    22646 |
      4. | 1/1/2022    22646 |
      5. | 1/1/2022    22646 |
         |-------------------|
      6. |    16252    16252 |
         +-------------------+

    Comment

    Working...
    X