BookmarkSubscribeRSS Feed
GPatel
Pyrite | Level 9

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

2 REPLIES 2
PhilC
Rhodochrosite | Level 12

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;

slchen
Lapis Lazuli | Level 10

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 948 views
  • 0 likes
  • 3 in conversation