<?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: Best method for comparing multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587956#M167965</link>
    <description>&lt;P&gt;Thanks for all the responses. Based on what people posted I read this paper to get a basic understanding of arrays:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/242-30.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/242-30.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I applied a couple of the solutions presented here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Method #1 - find first non missing variable then loop through all (non-missing) variables to check if they have a difference:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; want &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token statement"&gt;array&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt; var1&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;var3 &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  first_value&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;coalescec&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;of &lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;[&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;]&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  flag&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  do _n_&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; to &lt;SPAN class="token function"&gt;dim&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; while &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;not&lt;/SPAN&gt; flag&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
    &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;not&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;missing&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;[&lt;/SPAN&gt;_n_&lt;SPAN class="token punctuation"&gt;]&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; flag &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; first_value &lt;SPAN class="token operator"&gt;ne&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;[&lt;/SPAN&gt;_n_&lt;SPAN class="token punctuation"&gt;]&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  end&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Method # 2 - Create a new variable with all variables concatenated together. Then count the number of times the first non missing value occurs in the concatenated variable. Compare this count to the total number of non missing variables. If the counts are different then there is a difference among the variables:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; want&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;array&lt;/SPAN&gt; v &lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;:&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
k&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;cats&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;of v&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;count&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;k&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;strip&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;coalescec&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;of v&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;dim&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;v&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;cmiss&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;of v&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; flag&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;else&lt;/SPAN&gt; flag&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;drop&lt;/SPAN&gt; k&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I applied both methods to my data, about 35,000 rows, and got the same observations returned. Method #2 seem to have slightly better performance. Less real time, user cpu time, system cpu time and memory used. For this reason method # 2 is my preferred solution.&lt;/P&gt;</description>
    <pubDate>Wed, 11 Sep 2019 17:23:18 GMT</pubDate>
    <dc:creator>supp</dc:creator>
    <dc:date>2019-09-11T17:23:18Z</dc:date>
    <item>
      <title>Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587837#M167916</link>
      <description>&lt;P&gt;Hello SAS community. I am hopeful someone might have a better method for comparing three character variables within the same observations such that it identifies when two or more of the variables are different. Also, a null value in one of the variables should not be seen as different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hypothetical data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover;
input id $ var1 $ var2 $ var3 $;
datalines;
1 . A A
2 A A A
3 A . B
4 . A B
5 A B C
6 A A .
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data want would return ID's 3, 4 and 5 (there is at least one difference between the non missing values). It would not return ID's 1,2 or 6 (all non missing values are the same).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried a series of nested if-then do statements. For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if var1 ne '.' then do;
  if var2 ne '.' then do;
    if var1 ne var2;
  end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I might have gotten a variation (not exactly like the example above) to maybe work. Given the volume of data it is hard to be confident in my solution. I believe there is a much more elegant solution to this problem, any suggestions would be appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 13:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587837#M167916</guid>
      <dc:creator>supp</dc:creator>
      <dc:date>2019-09-11T13:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587844#M167917</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
infile datalines truncover;
input id $ var1 $ var2 $ var3 $;
datalines;
1 . A A
2 A A A
3 A . B
4 . A B
5 A B C
6 A A .
;
data want;
set have;
array v var:;
k=cats(of v(*));
if count(k,strip(coalescec(of v(*))))=dim(v)-cmiss(of v(*)) then flag=1;
else flag=0;
drop k;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Sep 2019 13:16:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587844#M167917</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-11T13:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587849#M167919</link>
      <description>&lt;P&gt;This is interesting logic, using COALESCEC in a way I would not have though of.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the real problem allows variables VAR1-VAR3 to take on arbitrary length character strings instead of character strings that have only a single character, I don't think this works any more. Of course, this is me reading between the lines; the original question didn't say that character strings VAR1-VAR3 could be more than one character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the more general case, I think you would need some sort of ARRAY to loop over all VAR1-VARn variables, and if a mismatch is found the flag is zero; if a mismatch is not found then the flag is one.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 13:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587849#M167919</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-09-11T13:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587857#M167923</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover;
input id $ var1 $ var2 $ var3 $;
datalines;
1 . A A
2 A A A
3 A . B
4 . A B
5 A B C
6 A A .
;

data want;
set have;
array v var:;
array temp(99999)$ _temporary_;
do _n_=1 to dim(v);
 if dim(temp)-cmiss(of temp(*))&amp;gt;0 then if  v(_n_) not in temp then do;
 flag=0;
 return;
 end;
 if v(_n_)&amp;gt;' ' then temp(_n_)=v(_n_);
end;
Flag=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Sep 2019 13:44:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587857#M167923</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-11T13:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587859#M167924</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
set have;
array v var:;
flag=1;
prev_non_missing=v(1);
do i=2 to dim(v);
	if not missing(v(i)) and not missing(prev_non_Missing) and v(i)^=v(i-1) then do;
		flag=0;
		leave;
	end;
	else if not missing(prev_non_missing) and missing(v(i)) then v(i)=prev_non_missing;
	else if missing(prev_non_missing) and not missing(v(i)) then prev_non_missing=v(i);
end;
drop i;
run;
	&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Sep 2019 13:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587859#M167924</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-09-11T13:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587861#M167925</link>
      <description>&lt;P&gt;You can just take the first non-missing value and then test to see if any other non-missing values exist.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input id $ var1 $ var2 $ var3 $;
datalines;
1 . A A
2 A A A
3 A . B
4 . A B
5 A B C
6 A A .
7 . . .
;

data want ;
  set have ;
  array var var1-var3 ;
  first_value=coalescec(of var[*]);
  flag=0;
  do _n_=1 to dim(var) while (not flag);
    if not missing(var[_n_]) then flag = first_value ne var[_n_];
  end;
run;

proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                                     first_
Obs    id    var1    var2    var3    value     flag

 1     1              A       A        A         0
 2     2      A       A       A        A         0
 3     3      A               B        A         1
 4     4              A       B        A         1
 5     5      A       B       C        A         1
 6     6      A       A                A         0
 7     7                                         0
&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Sep 2019 13:48:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587861#M167925</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-11T13:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587867#M167928</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    call sortc(of var:);
    flag=ifn(length(prxchange('s/(.)\1+/$1/', -1, cats(of var:))) &amp;gt; 1, 1, 0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 13:50:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587867#M167928</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-11T13:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587872#M167929</link>
      <description>&lt;P&gt;Note that using CALL SORTC() will change the order of the original values.&lt;/P&gt;
&lt;P&gt;Also I don't think that method works when the strings are longer than a single character.&lt;/P&gt;
&lt;P&gt;Try setting the values to the same multiple character values and see what happens.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also what value is the use of the IFN() doing in that code?&lt;/P&gt;
&lt;P&gt;It looks like you are using it to convert the results of the test for greater than one. So you are using it to convert 1 to 1 and 0 to 0.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 14:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587872#M167929</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-11T14:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587876#M167930</link>
      <description>&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;/*Or COUNTW is Simpler*/&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array v var:;
_k=coalescec(of v(*));
_n=dim(v)-cmiss(of v(*));
_k1=catx(' ',of v(*));
Flag=_n=countw(_k1,strip(_k));
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Sep 2019 14:35:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587876#M167930</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-11T14:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587879#M167931</link>
      <description>&lt;P&gt;Ah yes. Once again thank your for the sharp eye&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code should rather be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    call sortc(of var:);
    flag=length(prxchange('s/(.)\1+/$1/', -1, cats(of var:))) &amp;gt; 1;
    set have;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This way the order of var1-var3 will be intact in &lt;STRONG&gt;want&lt;/STRONG&gt; and the flag is set correctly. Don't need the ifn function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, this approach will not work if the variables are not single letters no &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 14:19:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587879#M167931</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-11T14:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587880#M167932</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;infile datalines truncover;&lt;BR /&gt;input id $ var1 $ var2 $ var3 $;&lt;/P&gt;&lt;P&gt;datalines;&lt;BR /&gt;1 . A A&lt;BR /&gt;2 A A A&lt;BR /&gt;3 A . B&lt;BR /&gt;4 . A B&lt;BR /&gt;5 A B C&lt;BR /&gt;6 A A .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;array x {3} var1 var2 var3 ;&lt;BR /&gt;do i= 1 to 1;&lt;BR /&gt;if i ne . then do;&lt;BR /&gt;if x{i} ne x{i+1} ne x{i+2} then output;&lt;BR /&gt;end;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you might modify it as per the amount of variables you have to check .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 14:15:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587880#M167932</guid>
      <dc:creator>Meghna14</dc:creator>
      <dc:date>2019-09-11T14:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587884#M167933</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For arbitrary length strings, i think a slightly modified version of &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;'s program&lt;/P&gt;
&lt;P&gt;should work :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if countw(catx(' ',of v(*)),strip(coalescec(of v(*))))=dim(v)-cmiss(of v(*)) then flag=1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Sep 2019 14:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587884#M167933</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-09-11T14:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587888#M167934</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18331"&gt;@supp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello SAS community. I am hopeful someone might have a better method for comparing three character variables within the same observations such that it identifies when two or more of the variables are different. Also, a null value in one of the variables should not be seen as different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hypothetical data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover;
input id $ var1 $ var2 $ var3 $;
datalines;
1 . A A
2 A A A
3 A . B
4 . A B
5 A B C
6 A A .
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data want would return ID's 3, 4 and 5 (there is at least one difference between the non missing values). It would not return ID's 1,2 or 6 (all non missing values are the same).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried a series of nested if-then do statements. For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if var1 ne '.' then do;
  if var2 ne '.' then do;
    if var1 ne var2;
  end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I might have gotten a variation (not exactly like the example above) to maybe work. Given the volume of data it is hard to be confident in my solution. I believe there is a much more elegant solution to this problem, any suggestions would be appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You are missing a couple pieces of potentially extremely critical information. Such as, are your character values single characters or longer? And are they something from a fixed list of values (you know what they are expected to be) or just sort of randomly entered text?&lt;/P&gt;
&lt;P&gt;Also is this case sensitive? Is "A" equal to "a" for this purpose?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have values that are fixed and case sensitive then this approach of creating a custom informat to assign a numeric value will work as what you are in effect requesting is "is the range of values = 0 or not". The following code could be adjusted to case insensitive by adding (UPCASE) after the name of the informat in the Invalue statement of the format. The variable dif will be 1 when there is a difference and 0 otherwise. The numeric values assigned to the values aren't critical as long as each is different though if you have a largish number of possible values a sequential assignment might be easier with a CNTLIN data set for Proc Format.&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
invalue mychars
'A' = 1
'B' = 2
'C' = 3
;
run;

data have;
   infile datalines truncover;
   input id $ var1 $ var2 $ var3 $;
   array vc var1 - var3;
   array vn{3};
   do i=1 to dim(vc);
      vn[i]= input(vc[i],mychars.);
   end;&lt;BR /&gt;   drop I vn: ;
   dif = (range(of vn(*)) &amp;gt; 0);
datalines;
1 . A A
2 A A A
3 A . B
4 . A B
5 A B C
6 A A .
;

 
&lt;/PRE&gt;
&lt;P&gt;Note that if you have&amp;nbsp;larger number of variables with the same value list this is easily extendable to more variables. &amp;nbsp;Just increase the array definitions.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 14:41:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587888#M167934</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-11T14:41:35Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587893#M167936</link>
      <description>&lt;P&gt;It is easily extendable to handle more than one-character strings though&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input id $ var1 $ var2 $ var3 $;
datalines;
1 .  AB AB
2 AB AB AB
3 AB . BA 
4 .  AB BA
5 AB BA CD
6 AB AB . 
7 .  .  . 
;

data want;
    set have;
    call sortc(of var:);
    flag=countw(prxchange('s/\b(\w+)(?:\W+\1\b)+/$1/', -1, catx(' ', of var:)), ' ') &amp;gt; 1;
    set have;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Sep 2019 15:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587893#M167936</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-11T15:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587933#M167952</link>
      <description>Can you elaborate on why the solution wouldn't work for character strings more than one character?</description>
      <pubDate>Wed, 11 Sep 2019 16:54:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587933#M167952</guid>
      <dc:creator>supp</dc:creator>
      <dc:date>2019-09-11T16:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587951#M167962</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18331"&gt;@supp&lt;/a&gt;&amp;nbsp; Requesting you to please test with a small sample. I am intrigued too coz that solution seem not to have anything to do with length rather deals with value. However, I didn't test extensively, and I might later when I have some time.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;The logic is simple:&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;1. concatenate the contents of the array. Cats would have removed leading and trailing blanks&lt;/P&gt;
&lt;P&gt;2. Identify the 1st non-missing value with coalescec within the contents of the array&lt;/P&gt;
&lt;P&gt;3.&amp;nbsp;dim(v)-cmiss(of v(*)) gives us the number of non-missing elements in the array&lt;/P&gt;
&lt;P&gt;4. Logic: Check if the count of the 1st non-missing value is equal to the number of non-missing elements in the array with count function. If yes , the elements are the same, and if false obviously otherwise&lt;/P&gt;
&lt;P&gt;5. Hence, i am not sure what has this got to do with length of any sort. Sometimes, i code too fast and I tend to miss out some intricacies, so test and let me know plz.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 17:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587951#M167962</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-11T17:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587956#M167965</link>
      <description>&lt;P&gt;Thanks for all the responses. Based on what people posted I read this paper to get a basic understanding of arrays:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/242-30.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/242-30.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I applied a couple of the solutions presented here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Method #1 - find first non missing variable then loop through all (non-missing) variables to check if they have a difference:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; want &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token statement"&gt;array&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt; var1&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;var3 &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  first_value&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;coalescec&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;of &lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;[&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;]&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  flag&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  do _n_&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; to &lt;SPAN class="token function"&gt;dim&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; while &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;not&lt;/SPAN&gt; flag&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
    &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;not&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;missing&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;[&lt;/SPAN&gt;_n_&lt;SPAN class="token punctuation"&gt;]&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; flag &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; first_value &lt;SPAN class="token operator"&gt;ne&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;[&lt;/SPAN&gt;_n_&lt;SPAN class="token punctuation"&gt;]&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  end&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Method # 2 - Create a new variable with all variables concatenated together. Then count the number of times the first non missing value occurs in the concatenated variable. Compare this count to the total number of non missing variables. If the counts are different then there is a difference among the variables:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; want&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;array&lt;/SPAN&gt; v &lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;:&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
k&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;cats&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;of v&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;count&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;k&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;strip&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;coalescec&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;of v&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;dim&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;v&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;cmiss&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;of v&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; flag&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;else&lt;/SPAN&gt; flag&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;drop&lt;/SPAN&gt; k&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I applied both methods to my data, about 35,000 rows, and got the same observations returned. Method #2 seem to have slightly better performance. Less real time, user cpu time, system cpu time and memory used. For this reason method # 2 is my preferred solution.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 17:23:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/587956#M167965</guid>
      <dc:creator>supp</dc:creator>
      <dc:date>2019-09-11T17:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/588086#M168020</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Very clever indeed.&lt;/P&gt;
&lt;P&gt;However, I can't help but note that CATS in situations like this or similar is dangerous because of its &lt;EM&gt;scrambling effect&lt;/EM&gt;. For example, your solution will readily break on something as simple as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                 
  input id (var1-var3) ($) ;
  cards ;                   
1 AB A B                    
;                           
run ;                       
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The obvious reason is that (AB A B) is scrambled to (ABAB), and any algorithm looking for something different from AB will say that all VAR values are equal.&amp;nbsp;Of course, you can modify your code using CATX instead. But there's another caveat: The buffer of any feline function (and also others like REPEAT) is limited to 32767; and so if the sum of the non-blank lengths of the VAR: should exceed 32767, it can break the code because of the truncation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Methinks in this situation (and situations similar to this), a general solution devoid of the above pitfalls&amp;nbsp; is possible only via array processing following the logic:&lt;/P&gt;
&lt;DIV&gt;(1) Find the first (or last) non-missing value.&lt;/DIV&gt;
&lt;DIV&gt;(2) See if any subsequent (or preceding) non-missing value is different; and if so, break the loop.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;For example:&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                      
  input id (V1-V3) ($) ;      
  cards ;                        
1 .  AB AB                        
2 AA AA AA                        
3 AA .  BB                        
4 .  AA BB                        
5 AA BB CC                        
6 AA AA .                        
7 .  AA .                        
8 .  .  .                        
9 AB A  B&lt;BR /&gt;;                                
run ;                            
                                 
data want (drop = _:) ;          
  set have ;                      
  array vv v: ;                  
  do over vv ;                    
    if cmiss (vv) then continue ;
    _n + 1 ;                      
    if _n = 1 then _v = vv ;      
    else if vv ne _v then do ;    
      unequal_flag = 1 ;          
      leave ;                    
    end ;                        
  end ;                          
  unequal_flag = ^^ unequal_flag ;
run ;                            &lt;/CODE&gt;&lt;/PRE&gt;
It's by far not as elegant as your offering, but it's not going to break on scrambling or insufficient buffer length.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Kind regards&lt;/DIV&gt;
&lt;DIV&gt;Paul D.&lt;/DIV&gt;</description>
      <pubDate>Thu, 12 Sep 2019 03:41:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/588086#M168020</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-09-12T03:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/588179#M168066</link>
      <description>&lt;P&gt;Guru&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp; Very interesting insight and rationale. Honestly the buffer thing never clicked to me. I guess the tendency of me treating each one like a fun video game rather a&amp;nbsp; real technical solution shows that I lack maturity. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; Nonetheless, that specialist professional demeanor&amp;nbsp; is something I am gradually learning from you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS&amp;nbsp; Though both of us live in the same time zone, I request you to kindly bear with&amp;nbsp; delays in me acknowledging your post as it seems I am missing out quite a bit on some threads while I am sleeping and you are wide awake as I noticed this while brushing my teeth this morning. Also you are aware I try to follow your posts in the ones I didn't participate, and indeed the value is priceless.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2019 11:50:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/588179#M168066</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-12T11:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: Best method for comparing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/588195#M168074</link>
      <description>&lt;PRE&gt;data have;
  infile datalines truncover;
  input id $ var1 $ var2 $ var3 $;
datalines;
1 . A A
2 A A A
3 A . B
4 . A B
5 A B C
6 A A .
7 . . .
;
data want;
 if _n_=1 then do;
   length k $ 80;
   declare hash h();
   h.definekey('k');
   h.definedone();
 end;
set have;
array x{*} $ var: ;
do i=1 to dim(x);
  if not missing(x{i}) then do;k=x{i};h.ref(); end;
end;
if h.num_items&amp;gt;1 ;
h.clear();
drop i k;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Sep 2019 12:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-method-for-comparing-multiple-variables/m-p/588195#M168074</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-09-12T12:54:44Z</dc:date>
    </item>
  </channel>
</rss>

