You can transform you question to a query:
data have;
input name$ num1 num2 num3 num4;
cards;
a 1 2 3 4
b 1 2 3 4
c 1 3 4 2
;
run;
proc sql noprint;
create table want as
select
count(distinct name)=1 as name,
count(distinct num1)=1 as num1,
count(distinct num2)=1 as num2,
count(distinct num3)=1 as num3,
count(distinct num4)=1 as num4
from have;
quit;
The count(distinct var) can handel both numeric and character variables. Run the program, the result will be one row:
name
num1
num2
num3
num4
0
1
0
0
0
To avoid writing the query statement manual, make it be data-driven:
proc contents data=have out=_attr_ noprint;
run;
data _null_;
set _attr_ end=eof;
if _n_=1 then call execute('proc sql noprint; create table want as select');
call execute(ifc(_n_>1,',','')||'count(distinct '||trim(name)||')=1 as '||name);
if eof then call execute(' from have; quit;');
run;
By default, the count() function doesn't count missing values, if you want to take missing values into the game, you can convert the variables' value type:
proc sql noprint;
create table want as
select
count(distinct cats(name))=1 as name,
count(distinct cats(num1))=1 as num1,
count(distinct cats(num2))=1 as num2,
count(distinct cats(num3))=1 as num3,
count(distinct cats(num4))=1 as num4
from have;
quit;
... View more