BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tushar
Obsidian | Level 7

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');

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
%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 ;

View solution in original post

3 REPLIES 3
Ksharp
Super User
%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 ;
Tushar
Obsidian | Level 7
Thanks it worked 🙂

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 459 views
  • 1 like
  • 2 in conversation