Announcement

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

  • Search for text component in string variables

    Hi all,

    I have a string variable in my dataset that contains a list of secondary diagnosis codes (e.g J13, J09.5 etc). I am trying to create a new numeric variable that should be 1 if certain codes (J13,J14,J15) are included in my secondary diagnosis codes. Which command can I best use for this?

  • #2
    Sounds like

    Code:
    gen wanted = strpos(diagnosis, "J13") | strpos(diagnosis, "J14") | strpos(diagnosis, "J15")
    strpos() returns a positive result if the specified text is found. Think of the numbers returned as #1 #2 #3 in any observation.The result of #1 | #2 | #3 is 1 if any of those numbers is positive (strictly, not zero) and 0 if all those numbers are zero.

    Comment


    • #3
      That works, thanks!

      Comment

      Working...
      X