An array would only be useful if you have multiple variables you wanted to reference.
But that is not what I took your statements to mean. Instead if sounds like you have just TWO variables, both of which have space delimited lists of words.
data have;
infile cards dsd truncover ;
input (a b) (:$50.);
cards;
VAR1 VAR2 VAR4,VAR3 VAR4
x y z,a X c
;
So make a new variable (or just update one of the existing ones).
data want;
set have;
length all $100 ;
all=a;
do i=1 to countw(b,' ');
if 0=findw(all,scan(b,i,' '),' ','i') then all=catx(' ',all,scan(b,i,' '));
end;
drop i;
run;
Result
But it would be simpler if your data structure just had one word per observation.
data have;
input type :$10. name :$32. ;
cards;
a VAR1
a VAR2
a VAR4
b VAR3
b VAR4
;
proc sql;
create table want as
select distinct name from have
;
quit;
... View more