Hello @Dritan007,
I see Tom was faster, but see a few additional suggestions below.
Use the NLEVELS option of PROC FREQ:
ods select none;
ods output nlevels=nlev;
proc freq data=given nlevels;
*tables _character_;
run;
ods select all;
proc sql noprint;
select tablevar into: dichovars separated by ' '
from nlev
where nlevels=2; /* or perhaps: where nnonmisslevels=2; */
quit;
data want;
set given(keep=id &dichovars);
run;
The TABLES statement (commented out) might be useful to obtain separate lists of numeric and character variables (needed for array definitions). The numbers in the NLEVELS variable in dataset NLEV include missing values in the counts, i.e., a variable with one missing value and value 0 otherwise would satisfy the WHERE condition, but not the alternative condition in the comment.
... View more