<?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: Variable Subset of Other Variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Variable-Subset-of-Other-Variable/m-p/783099#M249662</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards delimiter='|';
input V1 $ V2 $;
cards;
 	        |a1
a1, b1	    |a1
b2, b3, c6	|b2
c4, b2	    |b2
BO	        |a1
;
run;

data want;
 set have;
 Match = (INDEX(trim(left(upcase(V1))), trim(left(upcase(V2)))) gt 0);
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Most functions have &lt;EM&gt;modifiers&lt;/EM&gt; as optional additional arguments to make the function case insensitive, get rid of leading and/or trailing blanks in the comparison and so on.&lt;BR /&gt;I haven't checked in the doc if this is the case for the INDEX function so I do &lt;FONT face="courier new,courier"&gt;trim(left(upcase()))&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
    <pubDate>Tue, 30 Nov 2021 10:11:54 GMT</pubDate>
    <dc:creator>sbxkoenk</dc:creator>
    <dc:date>2021-11-30T10:11:54Z</dc:date>
    <item>
      <title>Variable Subset of Other Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-Subset-of-Other-Variable/m-p/783096#M249660</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi everyone&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to add a variable to my data that indicates wether or not the value in V1 matches the value in V2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;V1 is actually mostly empty, most rows don't contain a value. If there is a value, it can be any combination of the values possible for V2 separated by a comma (,). I've sketched a bit of an example.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;More general, I want to check if the string/character(?) in V2 shows up in V1, regardless of order or size.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;V1&lt;/TD&gt;&lt;TD&gt;V2&lt;/TD&gt;&lt;TD&gt;Match&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;a1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;a1, b1&lt;/TD&gt;&lt;TD&gt;a1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;b2, b3, c6&lt;/TD&gt;&lt;TD&gt;b2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;c4, b2&lt;/TD&gt;&lt;TD&gt;b2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;BO&lt;/TD&gt;&lt;TD&gt;a1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried something with find, but I think I get an error related to the missings in V1?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA my_data;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Match = FIND(Var1, Var2) gt 0;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm very new to SAS, so sorry if I made a silly mistake. Thanks a bunch though!&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 10:00:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-Subset-of-Other-Variable/m-p/783096#M249660</guid>
      <dc:creator>cmues</dc:creator>
      <dc:date>2021-11-30T10:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: Variable Subset of Other Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-Subset-of-Other-Variable/m-p/783097#M249661</link>
      <description>&lt;P&gt;Get rid of leading/trailing blanks in the string you are searching for:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm="09"x dsd truncover;
input V1 $ V2 $;
datalines;
 	a1
a1, b1	a1
b2, b3, c6	b2
c4, b2	b2
BO	a1
;

data want;
set have;
match = findw(v1,strip(v2)," ,") &amp;gt; 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And please supply your example data in the future in manner like above (data step with datalines), so we immediately have something to develop and test code against without having to make guesses about variable attributes and content.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 10:05:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-Subset-of-Other-Variable/m-p/783097#M249661</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-30T10:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: Variable Subset of Other Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-Subset-of-Other-Variable/m-p/783099#M249662</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards delimiter='|';
input V1 $ V2 $;
cards;
 	        |a1
a1, b1	    |a1
b2, b3, c6	|b2
c4, b2	    |b2
BO	        |a1
;
run;

data want;
 set have;
 Match = (INDEX(trim(left(upcase(V1))), trim(left(upcase(V2)))) gt 0);
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Most functions have &lt;EM&gt;modifiers&lt;/EM&gt; as optional additional arguments to make the function case insensitive, get rid of leading and/or trailing blanks in the comparison and so on.&lt;BR /&gt;I haven't checked in the doc if this is the case for the INDEX function so I do &lt;FONT face="courier new,courier"&gt;trim(left(upcase()))&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 10:11:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-Subset-of-Other-Variable/m-p/783099#M249662</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-11-30T10:11:54Z</dc:date>
    </item>
  </channel>
</rss>

