BookmarkSubscribeRSS Feed

LEXCOMBI

Started ‎02-20-2015 by
Modified ‎01-03-2020 by
Views 119,300

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;

 

 

 

 
 
2-20-2015 7-46-57 AM.png
Version history
Last update:
‎01-03-2020 10:02 AM
Updated by:

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Labels
Article Tags