Announcement

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

  • remove extra values from a double variable

    I want to multiply 2 variables (Strength_unit x ratio and generate a new variable that take the new value, but the proble is strength unit have extra numbers and details that I am not intrested I just need the first value before the node. for example for first row I just need 5. how can I do this
    Strength unit ratio
    5.000microgram/1.000hour 1.8
    15.000mg 015

  • #2
    Code:
    clear
    input str30 strength_unit float    ratio
    "5.000microgram/1.000hour"    1.8
    "15.000mg"                    015
    end
    
    gen strength_num = real(ustrregexs(0)) if ustrregexm(strength_unit,"^([0-9.]+)")
    which produces:

    Code:
    . li , noobs
    
      +---------------------------------------------+
      |            strength_unit   ratio   streng~m |
      |---------------------------------------------|
      | 5.000microgram/1.000hour     1.8          5 |
      |                 15.000mg      15         15 |
      +---------------------------------------------+

    Comment


    • #3
      Thank you, the code worked

      Comment

      Working...
      X