View
246
Download
0
Category
Tags:
Preview:
Citation preview
Manage Variable Lists with Macro Variables
1
for Improved Readability and Modifiability
The Problem/Opportunity
• Lists of variables occur frequently• Hard for others to read/verify • Samenesses/differences not apparent• Often have sublists and variations
Proposed Solution
• Assign each sublist to a macro variable• Name the macro variables informatively• Use as needed in executable code• Manipulate macroed string for alterations
Example Code
4
Title1 Explore distributions of independent variables;
proc freq data=ChemoData; table race gender region prevCancer stage grade insur/missing;...;
proc univariate data=ChemoData; var age BMI dateDiag income; histogram;...
Example Code (2)
5
Title1 Check for multicolinearity; proc reg data=ChemoData; model chemoRecvd = age BMI dateDiag income/vif;
Title1 Perform logistic regression; proc logistic data=ChemoData simple desc; class race gender region prevCancer stage grade insur /param=ref desc; model chemoDi = race gender region prevCancer
stage grade insur age BMI dateDiag income/scale=none rsq lackfit;
Assign the Lists
6
%let cateVars=race gender region prevCancer stage grade insur;%let contVars=age BMI dateDiag income;...
Example Code
7
Title1 Explore distributions of independent variables;
proc freq data=ChemoData; table &cateVars /missing;...;
proc univariate data=ChemoData; var &contVars; histogram;...
Example Code
8
Title1 Check for multicolinearity in continuous IVs; proc reg data=ChemoData; model chemoRecvd = &contVars /vif;run;Title1 Perform logistic regression; proc logistic data=ChemoData simple desc; class &cateVars /param=ref desc; model chemoDi = &cateVars &contIndVars /scale=none rsq lackfit
Handling Alterations/Variations
• Change the number of categories used for a variable
• Drop uninformative variables• Add variables for portion of analysis• => Can do all of these without cut/paste• => Can make the alterations explicit
Replacing a Variable
10
%macro replaceWord( /*in macro string */ inStr=, /*list of words altered*/ swapOut= /*word replaced list*/, swapIn=, /*replacement word*/ resMacVar= /*macvar receiving result*/);
%let newList=; *Use just 2 race categor;%replaceWord(inStr=&cateVars,swapOut=race , swapIn=race2c, resMacVar=newList);
Removing Variables
11
%macro removeWords( wordList=, /*words to remove*/ inMacVar=, /*list of words to alter*/ outMacVar= /*result list of words*/);
%let newList=; *Drop uninformative vars;%removeWords(wordList=race insur, inMacVar=cateVars, outMacVar=newList);
Take Aways
• Long list of vars need occur only once• Readability benefits when lists are named • Modifiability benefits when occur only once • Both benefit when alterations are explicit
Just do it!
For More Information
David.Abbott@va.gov
Recommended