SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
muhuri
Calcite | Level 5

I am using PRXMATCH with a Perl regular expression(RegEx) in a WHERE clause in PROC PRINT. The RegEx includes a macro variable containing a drug list and one of these drug names includes a forward slash.  I am getting an error even after using a escape character (back slash) in the RegEx.  I would appreciate your help resolve the issue.

Partial SAS Log:

ERROR: Invalid characters "ATROP \//i" after end delimiter "/" of regular expression
"/Propantheline|Propoxyphene|Reserpine|Ticlopidine|Trimethobenzamide|DIPHEN/ATROP \//i".

* Create a macro variable of study drugs;
%let STUDY_DRUG_LIST = Propantheline|Propoxyphene|Reserpine|Ticlopidine|Trimethobenzamide|DIPHEN/ATROP;

* Create an example data set of prescription fills (patient ID and drug names) ;
Data work.pmed;
input dupersid: $10.  rxname $20.;
datalines;
2320038102 NITROFURANTN
2320038102 EZETIMIBE
2320038102 Propantheline
2320040101 Reserpine
2320040101 Reserpine
2320040101 NOVOLOG
2320040101 NOVOLOG
2320040105 DIPHEN/ATROP
2320040105 DIPHEN/ATROP
2320040105 DIPHEN/ATROP
;

* List observations using PRXMATCH with a Perl regular expression in the WHERE clause (Study drug list);
proc print data=work.pmed;
where prxmatch ("/&study_drug_list2 \//i", rxname);
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

You need to escape the slash:

%let study_drug_list = Propantheline|Propoxyphene|Reserpine|Ticlopidine|Trimethobenzamide|DIPHEN\/TROP;

You can do that on the fly if needed:

%let study_drug_list2 = %sysfunc(transtrn(&study_drug_list,/,\/));

Then:

where prxmatch ("/&study_drug_list2/i", RXNAME);

 

View solution in original post

4 REPLIES 4
muhuri
Calcite | Level 5
Corrected: where prxmatch ("/&study_drug_list\//i", rxname);
ChrisNZ
Tourmaline | Level 20

You need to escape the slash:

%let study_drug_list = Propantheline|Propoxyphene|Reserpine|Ticlopidine|Trimethobenzamide|DIPHEN\/TROP;

You can do that on the fly if needed:

%let study_drug_list2 = %sysfunc(transtrn(&study_drug_list,/,\/));

Then:

where prxmatch ("/&study_drug_list2/i", RXNAME);

 

muhuri
Calcite | Level 5

Your revisions to my code have worked. Thanks,

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1233 views
  • 2 likes
  • 2 in conversation