I imagine that data A looks like
[pre]data A;
input a b c d e f g h i;
datalines;
1 2 3 4 5 6 7 8 9
9 8 7 6 5 4 3 2 1
3 4 5 6 1 2 7 8 9
;
run;[/pre]
From here I have to suggetions based on two different B's - both will result in the same 'new' A called analysis.
1)[pre]data B;
length var used $1;
input var used;
datalines;
B Y
C Y
F Y
A N
;
run;
data _null_;
length _x_ $2000;
retain _x_;
set B(where=(used='Y')) end=last;
_x_ = catx(' ',_x_,var);
if last then call symput('a_vars',strip(_x_));
run;
%put &a_vars.;
data analysis;
set A(keep=&a_vars.);
run;[/pre]
2)[pre]data B;
length B C F $1;
input b c f a;
datalines;
Y Y Y N
;
run;
proc sql NOPRINT;
select name into :varnames SEPARATED by ' '
from sashelp.vcolumn
where libname = 'WORK' and memname = 'B';
select nvar into :nvar
from sashelp.vtable
where libname = 'WORK' and memname = 'INPUT';
quit;
%put &varnames.;
data _null_;
length x $44 _x_ $2000;
set B;
do i = 1 to &nvar;
x=scan("&varnames",i,' ');
v = vvaluex(x); put v=;
if v = 'Y' then _x_ = catx(' ',_x_,x);
end;
call symput('a_vars',_x_);
run;
%put &a_vars;
data analysis;
set A(keep=&a_vars.);
run;[/pre]