Help using Base SAS procedures

Need help on PRXCHANGE function

Reply
Contributor
Posts: 69

Need help on PRXCHANGE function

I have following SAS Code, and need help with PRXCHANGE function.

Output of SAS code below is attached in an Excel file.

Data A  ;

Set MisMatch;    

IF Index(DrugName,'MG') > 0 then do;

var2=prxchange("s/[^0-9]//",-1,Drug_Strength);

var3=prxchange("s/[^A-Z]//",-1,Drug_Strength);

end;

run;

See the records (in Excel file) # 65,68-70,72-77,87-89. How can I get correct results using PRXCHANGE function?

The goal is to match Drug_Strength in a Drugname string.

If there is a better way, please let me know.

Regards,

Girish Patel

Regular Contributor
Posts: 170

Re: Need help on PRXCHANGE function

Hi, I don't think PRXCHANGE is the perfect match for what you are doing.  I think you want to identify the place in the string that the characters begin to be alphabetic, which signifies the beginning character position of the units.  PRXMATCH will help you start.  SUBSTR gets you the rest of the way.  Of course this fails us when Drug_Strength becomes something like "5MG-1000MG"

libname user "C:\MisMatch_C_07212015.xls";

Data L  ;
  if _N_ = 1 then do;
      retain PerlExpression;
      pattern = "/[A-Z]/";
      PerlExpression = prxparse(pattern);
  end;

  Set 'result#srx$'n (drop=var2 var3);

  length var2 var3 $ 32;
  IF Index(DrugName,'MG') > 0 then do;
    start = prxmatch(PerlExpression, Drug_Strength);
    if start>0 then do;
      var2=compress(substr(Drug_Strength,1,start-1));
      var3=compress(substr(Drug_Strength,start,32));
    end;
  end;
run;

Super Contributor
Posts: 275

Re: Need help on PRXCHANGE function

data want;

   set string;

   IF Index(DrugName,'MG') > 0 then do;

   _var2=prxchange('s/[^0-9-.]//i',-1,drug_strength);

   _var3=prxchange('s/[^a-z\/]//i',-1,drug_strength);

   end;

run;

Ask a Question
Discussion stats
  • 2 replies
  • 323 views
  • 0 likes
  • 3 in conversation