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 ;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.