SAS: Passing in Array Names -


i'm working on code change coding of several hundred variables stored 1/0 or y/n in numeric 1 or 0. because need in flexible process, writing macro so. issue have macro unable pass sas column names macro work. thoughts?

%macro test(s,e); %array(a,&s.-&e.); %mend;  data subset;     set dataset);     %test(v1,v20) run; 

sas supports variable lists. macro parameters text strings. long use macro variable value in place sas supports variable lists there no problem passing variable list macro. example here simplistic macro make array statement.

%macro array(name,varlist);   array &name &varlist ; %mend; 

which use in middle of data step this.

data want;   set have ;   %array(binary,var1-var20 a--d male education);   on binary; binary=binary in ('y','1','t'); end; run; 

the difficult part if want convert variables character numeric need rename them. make difficult use variable lists (x1-x5 or vara -- vard). can solve problem little logic convert variable lists list of individual names. example can use proc transpose create dataset variable names match list.

proc transpose data=&inds(obs=0) out=_names ;   var &varlist; run; 

you use dataset generate code or generate list of individual variable names.

proc sql noprint ;   select name :varlist2 separated ' ' _names; quit; 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -