1
votes

Please help me, a novice SAS user, figure this one out!

I have a variable (PERMITCL) that I need to recode. There are a few problems, however. First, the variable is different for almost every observation. Second, the length of the variable is also different in some cases.

Here are a few examples of observations:

01-01IIP
05-04
19-06ID
07-05
IIP

I want to know how many observations contain IIP.

I've tried using:

where prxmatch("m/IIP/oi", PERMITCL);

This is fine to some extent, but I'm still not happy with it. First, it doesn't keep any of the other observations; I'd prefer to keep them as zeroes or another identifier for later. Second, I still can't easily see how many total IIPs there are; a table yields a different line for each ##-##IIP and plain IIP.

How can I fix my issues?

1
Why does this question have a Perl tag? - Borodin
PRXMATCH() is a SAS function that uses perl style regular expressions. - Tom
regex is appropriate for questions about prxmatch, not perl. - Joe

1 Answers

2
votes

The purpose of a WHERE statement is to subset. Sounds like instead you want to calculate a new variable that you then sum or use for other things.

data want ;
  set have ;
  flag = prxmatch("m/IIP/oi",PERMITCL);
run;

proc freq ;
  tables flag ;
run;

The PRXMATCH() will return the location of the text in the string. If you want to convert it to a binary result then you could add more code. So you could do this instead:

  flag = (0 ne prxmatch("m/IIP/oi",PERMITCL)) ;