0
votes

I would like to create new columns variable using criteria matched in prxmatch.

The first variable 'NEW' is Y if: 
a. (A= "YES", B="NO" and C="PRESENT") or 
b. (B="NO" and C="MAYBE") or 
c. (B="NO" and C in ("NO/FL", "T2/FL ")) 
else N
The second variable 'NEXT' is Y if: 
A = 'NO' and B = 'NO' and E = 'Y'
else N 
and the last variable NEWER is Y if 
A = 'NEW' 

Below is my code but I can't get prxmatch() to work

DATA TEST; 
SET TEST.TEST; 
if A = 'NO' and B = 'YES' and C = 'PRESENT' then NEW = 'Y';
else if B = 'NO' and C = 'MAYBE' then NEW = 'Y';
else if prxmatch('m/NO/FL|T2/FL/oi', C) > 0 and B = 'NO' then NEW = 'Y';
else NEW = 'N';
if A = 'NO' and B = 'NO' and E = 'Y' then NEXT = 'Y';
else NEXT = 'N';
if A = 'NEW' then NEWER = 'Y';
 RUN; 

PROC PRINT DATA = TEST; 
RUN; 
1
You need to provide some sample data, so that someone can help you to understand why it is not working - Kiran
Is the information in the first code block actually textual data representing logic rules that need to be evaluated against the data ? - Richard

1 Answers

2
votes

the code for prxmatch did not wotk becacuse you have / and / is used for start and end of regular expression and whenever you have NO/FL it error's out because it your regular expression feels that it came to end and when it few more words after / it fails, so you need to NO/FL as NO\ /FL, without space as shown in below code.

 data have;
 input A $ B $ C $;
  datalines;
  NO YES PRESENT
  NO NO MAYBE
  NO NO NO/FL
 YES NO T2/FL
 ;

 DATA TEST; 
  SET have; 
 if A = 'NO' and B = 'YES' and C = 'PRESENT' then NEW = 'Y';
 else if B = 'NO' and C = 'MAYBE' then NEW = 'Y';
 else if prxmatch('m/NO\/FL|T2\/FL/oi', C) > 0 and B = 'NO' then NEW = 'Y';
 else NEW = 'N';
 RUN; 

  /* i would try something like below just for testing purpose to see how your code 
  works*/

     DATA TEST; 
    SET have; 
  if A = 'NO' and B = 'YES' and C = 'PRESENT' then NEW = 'Yah';
 else if B = 'NO' and C = 'MAYBE' then NEW = 'Yoh';
  else if prxmatch('m/NO\/FL|T2\/FL/oi', C) > 0 and B = 'NO' then NEW = 'Yay';
  else NEW = 'N';
 RUN;