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
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;
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.