Presentation is loading. Please wait.

Presentation is loading. Please wait.

Manage Variable Lists with Macro Variables 1 for Improved Readability and Modifiability.

Similar presentations


Presentation on theme: "Manage Variable Lists with Macro Variables 1 for Improved Readability and Modifiability."— Presentation transcript:

1 Manage Variable Lists with Macro Variables 1 for Improved Readability and Modifiability

2 The Problem/Opportunity Lists of variables occur frequentlyLists of variables occur frequently Hard for others to read/verifyHard for others to read/verify Samenesses/differences not apparentSamenesses/differences not apparent Often have sublists and variationsOften have sublists and variations

3 Proposed Solution Assign each sublist to a macro variableAssign each sublist to a macro variable Name the macro variables informativelyName the macro variables informatively Use as needed in executable codeUse as needed in executable code Manipulate macroed string for alterationsManipulate macroed string for alterations

4 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;...

5 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;

6 Assign the Lists 6 %let cateVars=race gender region prevCancer stage grade insur; %let contVars=age BMI dateDiag income;...

7 Example Code 7 Title1 Explore distributions of independent variables; proc freq data=ChemoData; table &cateVars /missing;...; proc univariate data=ChemoData; var &contVars; histogram;...

8 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

9 Handling Alterations/Variations Change the number of categories used for a variableChange the number of categories used for a variable Drop uninformative variablesDrop uninformative variables Add variables for portion of analysisAdd variables for portion of analysis => Can do all of these without cut/paste=> Can do all of these without cut/paste => Can make the alterations explicit=> Can make the alterations explicit

10 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);

11 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);

12 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!

13 For More Information David.Abbott@va.gov


Download ppt "Manage Variable Lists with Macro Variables 1 for Improved Readability and Modifiability."

Similar presentations


Ads by Google