UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

SAS Code Fragments
Creating a long list of variable names based on an abbreviated one

/***************************************************
   slist: an abbreviated list of variable names
          can be any SAS variable list
   flist: a global macro variable that is the
          expanded variable name list
***************************************************/
%macro varlist(data, slist);
  data _tiny_;
    set &data;
	keep &slist;
  run;
proc sql noprint;
  select name into :myvarlist separated by " "
  from sashelp.vcolumn
  where libname="WORK" and memname="_TINY_";
quit;
%let flist = &myvarlist;
%mend;
data test;
  array v(10);
  do j = 1 to 5;
  do i = 1 to 10;
    v(i) = i*5*j;
	ind = (i*j >30);
	end;
  output;
  end;
run;
%global flist;
%varlist(test, v:);
%put &flist;
122  %put &flist;
v1 v2 v3 v4 v5 v6 v7 v8 v9 v10

How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California