Not pretty or elegant but should be robust and scalable if you actually have more variables:
data have;
length name1 name2 name3 name4 $20;
input name1 name2 name3 name4;
row+1;
datalines;
B . A A
. B . .
A A A .
;
proc transpose data=have out=trans (where=( not missing(col1)) drop=_name_);
by row;
var name1-name4;
run;
proc sql;
create table temp as
select distinct row,col1
from trans;
quit;
data want;
set temp;
by row;
/* need to set length of a target to string
to at least longest possible so 20*number of variables+ number of variables
minus 1 for commas.
*/
length DistinctName $85;
retain DistinctName;
if first.row then DistinctName=col1;
else DistinctName= catx(',',DistinctName,col1);
distinctn= countw(DistinctName,',');
if last.row;
drop col1;
run;
Time to learn how to write a data step. That list of variables and output statements gets cumbersome quickly.
Also use the code box on the forum opened with the {I} or "running man" icons for posting code.
And just for curiosity how will that comma delimited list of "names" actually be used?
... View more