I have to roll-up a lot of locations but I'm able to look for keywords to classify them. I can accomplish this with multiple IF statements but would prefer to use IN and a wildcard or FINDW operator. I'm wondering if I can combine these. Here is the original method:
DATA want;
SET have;
if location = "STATE1A, CITY1" then new = "Group 1";
if location = "STATE1A, CITY2" then new = "Group 1"; if location = "STATE2B, CITY3" then new = "Group 1"; if location = "STATE2B, CITY4" then new = "Group 1";
if location = "STATE3A, CITY1" then new = "Group 2";
if location = "STATE3A, CITY2" then new = "Group 2"; if location = "STATE4B, CITY3" then new = "Group 2"; if location = "STATE4B, CITY4" then new = "Group 2";
RUN;
You can see that I'm only concerned about STATE1, STATE2, etc, regardless of the city. I need to search each observation for the correct State name (there can be 5-6 different ones), and I'm not concerned about the city name. The state name is varying lengths in the string. If I wanted to look for just one state name I would do the below, but I need to include a few states within the IN() command.
IF FINDW(lowcase(location),"state1") > 0 then new = Group a;
I would like to try:
IF location IN(%STATE1A%, %STATE2B%) then new = "Group 1";
IF location IN(%STATE3A%, %STATE4B%) then new = "Group 2";
I'm unsure if I should be using the pattern matching with %, or the FINDW command within the IN()?
... View more