Hi,
I am trying to run a macro with the following input and it works perfect.
%medc(pdrug=drp1|drp2|drp3|drrp4, dset=data1);
But, if any special characters in the input such as the following, the macro doesnt work.
%medc(pdrug=drp1 w/drp5|drp2|drp3 w/drp5/drp6/drp7|drp4, dset=data1);
Any idea to let the macro recognise these special characters?
Thanks
'/' ' ' are special characters for macro device , you need mask them via %str()
%medc(pdrug=%str(drp1 w/drp5|drp2|drp3 w/drp5/drp6/drp7|drp4) , dset=data1);
@Ksharp: Thanks for the quick response.
However, program end up with follwoing error.
ERROR: The regular expression passed to the function PRXMATCH contains a syntax error.
@ari wrote:
@Ksharp: Thanks for the quick response.
However, program end up with follwoing error.
ERROR: The regular expression passed to the function PRXMATCH contains a syntax error.
Please show the macro call you used and the macro code. The log generated with Options MPRINT may be helpful as well.
'/' is keyword for PRX , you need add escape char '\' before it.
data data;
code='drp1 w/drp5';
run;
%macro medc(pdrug=,dset=,);
data &dset;
set data;
if prxmatch("m/&pdrug/oi", code)>0;
run;
%mend medc;
%medc(pdrug=drp1 w\/drp5|drp2|drp3 w\/drp5\/drp6\/drp7|drp4, dset=data1)
Is there a need to pass them as a macro paramter? Why not pass in a dataset with your list of parameters - it doesn't matter then how long your parameters are or what they contain. If you can provide some test data (form of a datastep) and what the output should like like I can show you.
I need to provide input as macro parameter to create datasets based on the match
%macro medc(str=,dset=,);
data &dset;
set data;
if prxmatch("m/&pdrug/oi", code)>0;
run;
%mend medc;
So, just as an example there (note, this is just a demo - it doesn't run, you need to update with your data/variables etc.):
data parameters; param="abc"; output; param="def"; output; run; %macro your_macro (ds=); proc sql; create table WANT as select A.VARIABLES, B.VARIABLES from BASE_DATASET A left join &DS. B on prxmatch(B.PARAM,A.CODE); quit; %mend your_macro; %your_macro (ds=parameters);
As always there is many ways of of doing it, you could just replace the list with the dataset, you could put all parameters in the dataset etc.
%conmd(pdrug=params, dset=ta ,flg=tac);
Or, all params in a dataset:
data params: param="Values"; item="T"; output; param="Values"; item="P": output; param="Dset"; item="ta"; output; param="Flg"; item="tac"; output; run; %macro temp (params=); ... %mend temp; %temp (params=params);
I don't know much of the PRX world, but it looks to me like your problem is with the regular expression, not the macro language.
If you remove the macro language, can you get the regular expression to work? It looks to me like your current macro would generate the below code, which fails with that error message.
39 data want; 40 set sashelp.class; 41 if prxmatch("m/drp1 w/drp5|drp2|drp3 w/drp5/drp6/drp7|drp4/oi", name)>0; 42 run; ERROR: Invalid characters "drp5|drp2|drp3 w/drp5/drp6/drp7|drp4/oi" after end delimiter "/" of regular expression "m/drp1 w/drp5|drp2|drp3 w/drp5/drp6/drp7|drp4/oi". ERROR: The regular expression passed to the function PRXMATCH contains a syntax error.
So maybe those blanks in your expression are a problem?
Often the first step of macro-debugging is figuring out whether it is the macro language throwing an error or the SAS language. And it often helps to back out of the macro language so that you figure out the SAS code that works first, then figure out how to use the macro language to generate that SAS code.
HTH.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: