Skip to content

Instantly share code, notes, and snippets.

@statgeek
Created March 17, 2014 16:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save statgeek/9603186 to your computer and use it in GitHub Desktop.
Save statgeek/9603186 to your computer and use it in GitHub Desktop.
SAS - Macro Loop Through Variable Lists
/*This Loops thoough a set of variables where the variables
are separated by "|". Any other delimiter can be used
and specified in the scan function as well*/
%macro loop(varlist);
%let i=1;
%do %while (%scan(&varlist, &i, |) ^=%str());
%let var=%scan(&varlist, &i, |);
%put &var;
*rest of SAS code goes here;
*Increment counter;
%let i=%eval(&i+1);
%end;
%mend;
%let temp=a|b|c|d|e;
%loop(&temp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment