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 ;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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: