The thread "Need help with sas macros" https://communities.sas.com/thread/71429 which has little to do with macro, got me to thinking about how this is a nice example of an application of LEXCOMBI.
Using LEXCOMBI allows the program to be parameterized with regard to the variables processed and the number of variables that are added together.
data test;
array _v[*] A B C D E (1:5);
do _n_ = 1 to 10;
do _i_ = 1 to dim(_v);
_v[_i_] = _v[_i_] * 2;
end;
output;
end;
drop _:;
run;
proc print;
run;
*parameters;
%let varlist=A-numeric-E;
%let k = 3;
data score;
retain _Type_ 'SCORE';
length _Name_ $32;
if 0 then set test(keep=&varlist); *get variables list into array;
array _varlist[*] &varlist;
array _i[&k] _temporary_; *dim(_varlist) choose dim(_i);
__n_ = dim(_varlist);
__k_ = dim(_i);
__ncomb_ = comb(__n_,__k_);
do __j_ = 1 to __ncomb_;
__rc_ = lexcombi(__n_,__k_,of _i[*]);
call missing(_name_,of _varlist[*]);
do __h_ = 1 to dim(_i);
__ii_ = _i[__h_]; *VNAME does not accept double subscript reference;
_name_ = catx('_',_name_,vname(_varlist[__ii_]));
_varlist[__ii_] = 1;
end;
output;
end;
stop;
drop __:; *double leading underscore so we can drop easily;
run;
proc print;
run;
proc score data=test score=score out=scored;
var a--e;
run;
proc print;
run;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.