<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Special characters in IN operator in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878563#M347116</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;I should not translate pipe to comma as there may be a value with comma between it (e.g. Firstname,Lastname) and it is valid.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not with the values of the macro variable you showed.&amp;nbsp; In your example all of the values where enclosed in quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try it yourself WITHOUT ANY MACRO CODE.&lt;/P&gt;
&lt;P&gt;So an expression like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where divison in ("ABC,XYZ","QRX");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where divison in ("ABC,XYZ" "QRX");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Will find the observations where DIVISION is either QRX or ABC,XYZ.&amp;nbsp; It will not find values of ABC or XYZ.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 31 May 2023 19:46:02 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-05-31T19:46:02Z</dc:date>
    <item>
      <title>Special characters in IN operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878504#M347089</link>
      <description>&lt;P&gt;Is there a way to use IN operator to look for the values separated by pipe (|) instead of comma?&amp;nbsp; Value of macro variable is separated by pipe and I want to use the same value in where clause of proc print. I cannot control the macro variable value with pipe as separators.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking for dynamic solution when&lt;SPAN&gt;&amp;nbsp;macro variable has either 1 or 3 or 4 values. e.g. ("Banking" or "Banking"|"Insurance"|"Textile")&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code:&lt;/P&gt;
&lt;PRE&gt;proc print data=have noobs;
where &amp;amp;value_1 IN (&amp;amp;value_2);
var &amp;amp;_field;
run;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;30   %put ####value_2 is: &amp;amp;value_2.;
####value_2 is: "Banking"|"Insurance"
31   
32   /*Filter and print the data*/
33           
34   proc print data=have noobs;
SYMBOLGEN:  Macro variable value_1 resolves to DIVISION
35   where &amp;amp;value_1 IN (&amp;amp;value_2);
SYMBOLGEN:  Macro variable value_2 resolves to "Banking"|"Insurance"
NOTE: Line generated by the macro variable "value_2".
35   "Banking"|"Insurance"
                               -
                               22
                               200
ERROR: Syntax error while parsing WHERE clause.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 May 2023 18:20:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878504#M347089</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-05-31T18:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: Special characters in IN operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878517#M347093</link>
      <description>&lt;P&gt;While not sure about whether IN operator could accept the PIPE as a delimiter,&amp;nbsp; I suggest using %scan function to separate pipe delimited values into individual values inside the parenthesis.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If macrovar has only 2 values then the following code would separate them into individual values to process using IN operator:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where &amp;amp;value_1 IN ("%scan(&amp;amp;value_2, 1, |)", "%scan(&amp;amp;value_2, 2, |)");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 May 2023 18:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878517#M347093</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-05-31T18:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Special characters in IN operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878520#M347095</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321371"&gt;@A_Kh&lt;/a&gt;&amp;nbsp; I guess that your solution is close enough. How to make your code dynamic i&lt;SPAN&gt;f macro variable has only 1 or 3 or 4 values?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 May 2023 18:18:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878520#M347095</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-05-31T18:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: Special characters in IN operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878522#M347096</link>
      <description>&lt;P&gt;You can translate the "|" to a comma, making the macro expression amenable to the IN operator:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let value2="Banking"|"Insurance";
%let cslist=%sysfunc(translate(&amp;amp;value2,%str(,),|));
%put &amp;amp;=cslist;
data want;
  set have; 
  where txt in (&amp;amp;cslist);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 May 2023 18:23:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878522#M347096</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-05-31T18:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Special characters in IN operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878523#M347097</link>
      <description>&lt;P&gt;If the values do not contain | then use TRANSLATE() to convert the | into comma or space.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where &amp;amp;value_1 IN ( %sysfunc(translate(&amp;amp;value_2,%str( ),|)) );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To generate code like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where DIVISION in ("Banking" "Insurance");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or use the FINDW() function instead of the IN operator.&lt;/P&gt;
&lt;P&gt;So use something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where quote(trim(&amp;amp;value_1)),%sysfunc(quote(&amp;amp;value_2)),'|');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To generate code like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where findw(quote(trim(DIVISION)),"""Banking""|""Insurance""",'|');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 May 2023 18:24:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878523#M347097</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-31T18:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: Special characters in IN operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878526#M347099</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;I should not translate pipe to comma as there may be a value with comma between it (e.g. Firstname,Lastname) and it is valid.&lt;/P&gt;</description>
      <pubDate>Wed, 31 May 2023 18:30:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878526#M347099</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-05-31T18:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: Special characters in IN operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878529#M347100</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;I tried this code and it yields only one record in the result instead of two.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let value2="Bank,ing"|"Insurance";
%let cslist=%sysfunc(translate(&amp;amp;value2,%str(,),|));
%put &amp;amp;=cslist;
data have;
input name $;
datalines;
Bank,ing
Insurance
;
run;
data want;
  set have; 
  where name in (%sysfunc(translate(&amp;amp;value2,%str(,),|)));
run;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;84   data have;
85   input name $;
86   datalines;
NOTE: The data set WORK.HAVE has 2 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      
89   ;
90   run;
91   data want;
92     set have;
93     where name in (%sysfunc(translate(&amp;amp;value2,%str(,),|)));
94   run;
NOTE: There were 1 observations read from the data set WORK.HAVE.
      WHERE name='Bank,ing';
NOTE: The data set WORK.WANT has 1 observations and 1 variables.&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 May 2023 18:43:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878529#M347100</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-05-31T18:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: Special characters in IN operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878531#M347102</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;I used your instruction to replace pipe with comma and it is producing one record in the result instead of two.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let value2="Bank,ing"|"Insurance";
%let cslist=%sysfunc(translate(&amp;amp;value2,%str(,),|));
%put &amp;amp;=cslist;
data have;
input name $;
datalines;
Bank,ing
Insurance
;
run;
data want;
  set have; 
  where name in ( %sysfunc(translate(&amp;amp;value2,%str(,),|)) );
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 May 2023 18:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878531#M347102</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-05-31T18:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: Special characters in IN operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878537#M347105</link>
      <description>&lt;P&gt;You can create dynamic statement using COUNTC function and %do block. However, the code should be in macro definition:&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro print;
	proc print data=HAVE;
	where &amp;amp;value_1 IN (%do i= 1 %to (%sysfunc(countc(&amp;amp;value_2, |))+1);
						"%scan(&amp;amp;value_2, &amp;amp;i, |)" 
						%end;);
	run; 
%mend;

%print;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 May 2023 19:02:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878537#M347105</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-05-31T19:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: Special characters in IN operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878538#M347106</link>
      <description>Your sample data isn't generating correctly (insurance has 9 characters default is 8). &lt;BR /&gt;&lt;BR /&gt;If it generates correctly it works.</description>
      <pubDate>Wed, 31 May 2023 19:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878538#M347106</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-31T19:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: Special characters in IN operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878563#M347116</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;I should not translate pipe to comma as there may be a value with comma between it (e.g. Firstname,Lastname) and it is valid.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not with the values of the macro variable you showed.&amp;nbsp; In your example all of the values where enclosed in quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try it yourself WITHOUT ANY MACRO CODE.&lt;/P&gt;
&lt;P&gt;So an expression like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where divison in ("ABC,XYZ","QRX");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where divison in ("ABC,XYZ" "QRX");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Will find the observations where DIVISION is either QRX or ABC,XYZ.&amp;nbsp; It will not find values of ABC or XYZ.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 May 2023 19:46:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Special-characters-in-IN-operator/m-p/878563#M347116</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-31T19:46:02Z</dc:date>
    </item>
  </channel>
</rss>

