Announcement

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

  • -nsplit-command-

    hi all,
    I recently installed -nsplit- in order to split a numeric variable into two segments. the first part of the variable is the date I am interested in and the second part is a time (not interested in)

    example: the variable labdate is in the form : "26mar2009 10:46:00" and is numeric so substr wont work. I want to isolate the 26mar2009 portion in %td format using -nsplit labdate,digits ( x x) gen(y y)- I cant seem to get this to work.

    I dont really want to convert labdate into a string variable then proceed since my dataset is HUGE.

    any thoughts?

    thanks
    Vishal

  • #2
    Well, "26mar2009 10:46:00" does look like a string to me.

    I guess your problem is this: You have a date-time that when formatted looks like a string. How do you extract the daily date?

    If so, you're right. That problem is nothing to do with string manipulation. So nsplit (from SSC, as you are asked to explain) can't help. You need the appropriate date function for that:

    Code:
    . clear
    
    . set obs 1
    number of observations (_N) was 0, now 1
    
    . gen string_in = "26mar2009 10:46:00"
    
    . gen double date_out = clock(string_in, "DMY hms")
    
    . format date_out %tc
    
    . gen wanted = dofc(date_out)
    
    . format wanted %td
    
    . l
    
         +-----------------------------------------------------+
         |          string_in             date_out      wanted |
         |-----------------------------------------------------|
      1. | 26mar2009 10:46:00   26mar2009 10:46:00   26mar2009 |
         +-----------------------------------------------------+

    Comment


    • #3
      Thanks Nick!! that helped big time!

      and worked perfect.

      Comment

      Working...
      X