sas

Pattern matching in any position of a variable value


suppose to have a dataset with a variable named "Event". How can I subset all rows containing the following: "Hosp"? Note that the variable values are sentences and hence "Hosp" can be in any part of the sentence.

I tried (but I'm not sure I'm doing it correctly):

(upper(a.Event) like "%Hosp%"

Note that a is my dataset in a sql piece of code.

Thank you in advance.


Solution

  • If you upcase then the literal criteria also needs to be uppercase.

    upcase(a.Event) like "%HOSP%
    

    SAS has other matching operators and functions, any of these can work and will return a non-zero value (true) when the match occurs.

    upcase(a.Event) contains 'HOSP'
    prxmatch('m/HOSP/i', a.event)
    find (a.event, 'hosp', 'i')