Announcement

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

  • problem with label values

    For the below sample data, I would like to replace the values for my variable with the numbers within parentheses (i.e., 1 to be replaced by 11, 2 to be replaced by 12). I tried decode command but it did not work.
    Thanks,
    NM

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte _predict
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    end
    label values _predict _predict
    label def _predict 1 "predict(pr outcome(11))", modify
    label def _predict 2 "predict(pr outcome(12))", modify

  • #2
    You started down the right path with -decode-. But then you need to extract the number from the resulting string.
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte _predict
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    2
    2
    2
    2
    2
    2
    2
    2
    2
    2
    end
    label values _predict _predict
    label def _predict 1 "predict(pr outcome(11))", modify
    label def _predict 2 "predict(pr outcome(12))", modify
    
    decode _predict, gen(wanted)
    replace wanted = ustrregexrf(wanted, "\D+(\d+)\D+", "$1")
    destring wanted, replace

    Comment

    Working...
    X