Announcement

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

  • syntax for replacing date/time in variable formatted as %tc

    Dear Statalisters -

    I am cleaning a lot of date/time data, formatted as %tc and need to make some edits to the values. I have found that I can easily edit a %td formatted variable by writing code along the lines of replace dt_flow = d(19 Aug 2006) if ptid==XXXXX but I have searched widely online and have not been able to find a way to modify a %tc variable as easily though I expect that this utility exists. Can anyone help with this code?

    Thanks so much,
    Alison

  • #2
    For %tc dates, the function equivalent to date() is clock()

    Comment


    • #3
      A display format such as %tc doesn't necessarily mean that a variable is a date and time. But assuming that yours is such, you probably will be best advised to use the clock() function to indicate what you want instead.

      I don't know where you searched, but the fountain-head is simply identified: help dates and times

      Comment


      • #4
        Thanks both. I did review the dates and times help however I was not able to find the proper syntax for replace, only for creating date/time variables or extracting parts.
        I appreciate any follow-ups that will guide my syntax for replacing, as I still have not figured it out. Based on the help, the clock function is as such:
        replace dt_tm_flow = clock(02 Jan 2008 02:00) if index_rh==9 & pt_id==710013
        but does not work for replace, only for gen. I believe the issue is that I am not trying to reassign a string variable as a date/time variable, but am trying to overwrite a date/time variable with a correction.
        Any assistance on how to write this using an an example with date and time?
        Thank you.
        Last edited by Alison El Ayadi; 09 Jun 2014, 15:16.

        Comment


        • #5
          Never say "does not work"! Insert smiley of choice, or not.

          Always say what the error is, an error message or something done that you didn't want or something not done that you did.

          The help for clock() explains that it needs two arguments at least, both of those being strings. You gave it one argument, so on that ground alone, you had an error.

          Code:
           
          . di %tc  clock("02 Jan 2008 02:00", "DMY hm")
          02jan2008 02:00:00

          Comment


          • #6
            Thank you, Nick. I appreciate your help.
            I had tried it both with and without the mask (in quotations), but had not put the date/time argument in quotations.
            So happy to have the solution.

            Comment

            Working...
            X