To avoid duplicates, compare the candidate word with the current set of concatenated values using the FINDW function, which returns a 0 if the candidate is not found as a "word" in the concatenation. "word" here means strings separated by '|':
data ex1;
input var1 $ var2 $ var3 $;
cards;
%a b f
b %c d
%g f %c
run;
data _null_;
set ex1 end=end_of_ex;
length mv $24;
retain mv ;
if var1=:'%' and findw(mv,trim(var1),'|')=0 then mv=catx('|',mv,var1);
if var2=:'%' and findw(mv,trim(var2),'|')=0 then mv=catx('|',mv,var2);
if var3=:'%' and findw(mv,trim(var3),'|')=0 then mv=catx('|',mv,var3);
if end_of_ex;
call symput('mvar',mv);
run;
%put %superq(mvar);
Now it's getting busy enough that you'll want to use an array of var1 & var2 & var3, and program a loop. Note the 2nd argument of the findw function is not var1, but trim(var1) - otherwise any trailing blanks in var1 will be included in the search for a matching string in the MV variable.
... View more