Hi I have below program,
%let cri=abc in ('ABD' ' AND AND' 'PAND-AND AND' ' AND -AND' 'ABC') AND def in ('ABD' 'AND AND' 'PAND-AND AND' 'AND -AND' 'ABC');
%let QUERY_CRITERIA_CMPRES=%sysfunc(compress(&cri.,()));
data _null_;
call symputx("QUERY_CRITERIA_PIPE",tranwrd("&QUERY_CRITERIA_CMPRES.","' AND ","'|"));
run;
%put &=QUERY_CRITERIA_PIPE;
its working for outside of single quote AND which is required but it is also replacing AND which is inside quote, however i need to replace AND with pipe '|' only which are not in single quote. Anyone help?
Expected output-
abc in ('ABD' ' AND AND' 'PAND-AND AND' ' AND -AND' 'ABC') | def in ('ABD' ' AND AND' 'PAND-AND AND' ' AND -AND' 'ABC');
%let cri=abc in ('ABD' ' AND AND' 'PAND-AND AND' ' AND -AND' 'ABC') AND def in ('ABD' 'AND AND' 'PAND-AND AND' 'AND -AND' 'ABC'); data have; have="&cri"; length want $ 200; do i=1 to countw(have,"'",'m'); if mod(i,2)=0 then want=catx(' ',want,quote(scan(have,i,"'",'m'),"'")); if mod(i,2)=1 then want=catx(' ',want,prxchange('s/AND/|/i',-1,scan(have,i,"'",'m'))); end; call symputx('want',want); run; %put &=cri; %put &=want ;
@Ksharp anyhelp?
%let cri=abc in ('ABD' ' AND AND' 'PAND-AND AND' ' AND -AND' 'ABC') AND def in ('ABD' 'AND AND' 'PAND-AND AND' 'AND -AND' 'ABC'); data have; have="&cri"; length want $ 200; do i=1 to countw(have,"'",'m'); if mod(i,2)=0 then want=catx(' ',want,quote(scan(have,i,"'",'m'),"'")); if mod(i,2)=1 then want=catx(' ',want,prxchange('s/AND/|/i',-1,scan(have,i,"'",'m'))); end; call symputx('want',want); run; %put &=cri; %put &=want ;
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 25. 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.