Announcement

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

  • Converting data variables when the values containing long digits

    Hi,

    I have search and tried several commands to handle the issue with date variables in the dataset. I want to convert it as 1/1/2023 etc or any proper format. Example below,

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double(Admission_Date Discharge_Date)
    1.8932832e+12  1.893456e+12
    1.8933696e+12  1.893456e+12
     1.893456e+12  1.893456e+12
    1.8926784e+12  1.893456e+12
    1.8935424e+12 1.8935424e+12
    1.8935424e+12 1.8935424e+12
    1.8933696e+12 1.8935424e+12
    1.8935424e+12 1.8936288e+12
    1.8935424e+12 1.8936288e+12
    1.8936288e+12 1.8936288e+12
    end

    Any help is appreciated!

  • #2
    All you need is to look at

    Code:
    help datetime 
    and ascertain that the function
    Code:
    dofc()
    will yield a daily date. Otherwise we can't comment on code you don't show to say where you went wrong.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double(Admission_Date Discharge_Date)
    1.8932832e+12  1.893456e+12
    1.8933696e+12  1.893456e+12
     1.893456e+12  1.893456e+12
    1.8926784e+12  1.893456e+12
    1.8935424e+12 1.8935424e+12
    1.8935424e+12 1.8935424e+12
    1.8933696e+12 1.8935424e+12
    1.8935424e+12 1.8936288e+12
    1.8935424e+12 1.8936288e+12
    1.8936288e+12 1.8936288e+12
    end
    
    . format A D %tc
    
    . gen Adm_day = dofc(Adm)
    
    . format Adm_day %td
    
    . l
    
         +-----------------------------------------------------+
         |     Admission_Date       Discharge_Date     Adm_day |
         |-----------------------------------------------------|
      1. | 30dec2019 00:00:00   01jan2020 00:00:00   30dec2019 |
      2. | 31dec2019 00:00:00   01jan2020 00:00:00   31dec2019 |
      3. | 01jan2020 00:00:00   01jan2020 00:00:00   01jan2020 |
      4. | 23dec2019 00:00:00   01jan2020 00:00:00   23dec2019 |
      5. | 02jan2020 00:00:00   02jan2020 00:00:00   02jan2020 |
         |-----------------------------------------------------|
      6. | 02jan2020 00:00:00   02jan2020 00:00:00   02jan2020 |
      7. | 31dec2019 00:00:00   02jan2020 00:00:00   31dec2019 |
      8. | 02jan2020 00:00:00   03jan2020 00:00:00   02jan2020 |
      9. | 02jan2020 00:00:00   03jan2020 00:00:00   02jan2020 |
     10. | 03jan2020 00:00:00   03jan2020 00:00:00   03jan2020 |
         +-----------------------------------------------------+
    
    .

    Comment


    • #3
      It works. I have looked at date(MDY). I was suspect of zeros at the end buy didn't thought it could be for clocks. I have tried to remove the last 4 digits but it wasn't work. Thanks!

      Comment

      Working...
      X