I developed a user-friendly SAS macro application to perform all possible mixed model selection of fixed effects including quadratic and cross products within a user-specified subset range in the presence of random and repeated measures effects using SAS PROC MIXED (Fernandez, 2007). This macro application, ALLMIXED will complement the model selection option currently available in the SAS PROC REG for multiple linear regressions and the SAS Proc GLMSELECT that focuses on the standard independently and identically distributed general linear model for univariate responses. Options are also included in this macro to select the best covariance structure associated with the user-specified fully saturated repeated measures model; to graphically explore and to detect statistical significance of user specified linear, quadratic, interaction terms for fixed effects; and to diagnose multicollinearity, via the VIF statistic for each continuous predictor, involved in each model selection step. Two model selection criteria, AICC (corrected Akaike Information Criterion) and MDL (minimal description length) are used in all possible model selection and summaries of the best model selection are compared graphically. In this community posting, I will describe the prescreening step of ALLMIXED model selection steps.
ALL POSSIBLE MODEL SELECTION STEPS
The recommended selection steps for performing the model selection in MIXED model is illustrated in Figure1. Although the recommended sequence of the steps is identified in the figure 1, it is not a requirement to follow the same sequence. Users are free to choose to run any model selection steps in any order they desire. However, before running these model selection steps the data format must be suitable for running the SAS PROC Mixed procedure. The following types of PC data formats can be used with the ALLMIXED macro: SAS temporary and permanent data files, Microsoft excel, COMMA or TAB delimited text file.
SAS 9.4 Modules required to run this macro:
Improved ALLMIXED SAS macro application
The original SAS macro application, I developed (Fernandez, 2007) is not compatible in SAS enterprise guide (SAS EG) or in SAS studio. Therefore, I am presenting an improved version of the ALLMIXED macro in this post. By using this improved ALLMIXED macro application, SAS users can effectively perform complete mixed model analysis in SAS studio or in SAS EG. First download and unzip the ALLMIXED.zip file specified in this post and save the contents to a custom folder such as C:\temp\allmixed. The extracted ALLMIXED zip file should include, compiled ALLMIXED macro catalog, five macro call files corresponding to six ALLMIXED model selection steps, and sample demo data used in the demo. In this article, I will present the steps needed to perform Step2-Initial Covariance selection in this post. Please follow the steps outlined in the previous post to perform step1- Prescreening (https://communities.sas.com/t5/SAS-Communities-Library/User-friendly-SAS-application-for-performing-...).
STEP2: Initial Repeated measures Covariance selection
In a repeated measures modeling, the best covariance structure describing the correlation among the repeated measures should be identified first. The best covariance structure can be identified from different user-specified covariance structures by comparing the AICC statistic computed in PROC MIXED using REML method and select the covariance type which gives the smallest AICC value. In this example, four different covariance types, CS, AR(1), TOEP, and UN are compared in the full saturated model containing two categorical effects (TRT and TIME) and 4 continuous fixed effects selected from the previous prescreening steps.
ALLMIXED SAS macro help – Step 2 Repeated measure covariance type selection
Descriptions and Explanation: Include the data type name (XLS, TAB, TXT, SAS, TMP) and name of the data set on which you would like to perform pre-screening.
Options / Examples:
SAS_SIMDATA1: Data type is permanent SAS (SD7SAS) and the SAS permanent data name is SIMDATA1
TMP_SIMDATA1: Data type is temporary SAS data and file name is SIMDATA1.
Descriptions and Explanation: Input the continuous response (dependent) variable name (or names). The name should match the variable names in the data. You can include multiple responses
Options / Examples:
Descriptions and Explanation: To start the variable pre-screening mode, enter yes. Pre-screening based on the LASSO method using the selection method SBC and the stop criterion NONE will be performed. This field should be left blank to run all other model selection steps.
Options / Examples:
Descriptions and Explanation: Input the names of the categorical variables that will be included in the CLASS statement in PROC Mixed.
Options / Examples:
Class= TRT time sub
Descriptions and Explanation: Input any numeric and categorical character to track the number of the analysis that you are running using this data. For example, if you input 1A, the output file created in this step would be called SIMDATA11A.ext.
Options / Examples:
Z = -1
Z = 1A
Descriptions and Explanation: Input the REPEATED statement and leave the covariance type blank.
Options / Examples:
Descriptions and Explanation: In case of repeated measures data, input the subject variable name. This forces the pre-screening to do initial selection at the subject level.
Options / Examples:
Sub = Sub
Descriptions and Explanation: List all the repeated measures covariance types.
Options / Examples:
Descriptions and Explanation: Option for viewing and saving all output files in a folder specified in input number 17.
WORD: Output and all SAS graphics are saved together in the user-specified folder as a single RTF format.
WEB: Output and graphics are saved in the user-specified folder as a single HTML file.
PDF: Output and graphics are saved in the user-specified folder and as a single PDF file.
TXT: Output is saved as a TXT file in all SAS versions. No output is displayed in the OUTPUT window. All graphic files are saved as PNG format in the user-specified folder.
Descriptions and Explanation: Input the full path of the folder containing the source data file.
Options / Examples:
Make sure that you include the backslash (\) at the end of the folder name.
OUTPUT= c:\temp\allmixed\
Descriptions and Explanation: To save the SAS graphics, data, and output files, input the output folder name. If the 14 field is left blank, the output files are saved in the default folder.
Options / Examples:
Dir2= C:\temp\allmixed\
In a repeated measures modeling, the best covariance structure describing the correlation among the repeated measures should be identified first. The best covariance structure can be identified from different
user-specified covariance structures by comparing the AICC statistic computed in PROC MIXED using REML method and select the covariance type which gives the smallest AICC value. In this example, four
different covariance types, CS, AR(1), TOEP, and UN are compared in the full saturated model containing two categorical effects (TRT and TIME) and four continuous fixed effects selected from the previous prescreening
steps. The results of initial covariance type selection are graphically displayed in Figure3 and based on ΔAICCj (AICCj - AICC min), AR(1) can be identified as the best covariance type. Therefore, AR(1)
covariance type will be used in the subsequent fixed effect selection. Refer the ALLMIXED2 macro help file available from the authors website for more information regarding inputting appropriate parameters.
Reference
Fernandez, G. (2007) Model Selection in PROC MIXED - A User-friendly SAS® Macro Application SAS Global Forum proceedings 191-2007
https://support.sas.com/resources/papers/proceedings/proceedings/forum2007/191-2007.pdf
After testing with the following dataset, it was revealed that the compiled ALLmix macro was hard coded to use a fixed variable in the input data set, which is the variable 'time'.
Because my testing data set does not have the 'time' variable, the macro failed to run.
I strongly suggest the author open the source of the compiled macro. Otherwise, it is hard for others to use it and nobody will use it in the future, though the author has contributed a lot of time to write the program!
In addition, the compiled macro only works under Windows SAS but not Linux SAS. For SAS OnDemand for Academics, due to its Linux SAS, the compiled macro can not run.
This is my testing codes:
libname allmix4 "C:\Users\cheng\Downloads\ALLmixed";
%let wd=C:\Users\cheng\Downloads\ALLmixed\;
options sasmstore=allmix4 mstored;
/*Generate data for testing*/
*https://facweb.cdm.depaul.edu/sjost/csc423/documents/glmselect-summary.pdf;
data analysisData testData;
drop i j;
array x{20} x1-x20;
do i=1 to 5000;
/* Continuous predictors */
do j=1 to 20;
x{j} = ranuni(1);
end;
/* Classification variables */
c1 = int(1.5+ranuni(1)*7);
c2 = 1 + mod(i,3);
c3 = int(ranuni(1)*15);
yTrue = 2 + 5*x17- 8*x5 + 7*x9*c2- 7*x1*x2 + 6*(c1=2) + 5*(c1=5);
y= yTrue + 6*rannor(1);
if ranuni(1) < 2/3 then output analysisData;
else output testData;
end;
run;
proc datasets nolist;
copy in=work out=Allmix4 move;
select analysisData;
run;
%allmixed
(
/* 1. Input the Excel or sas Data set name? E.G: xls_simdata1 xlsx_simdata1 sas_simdata1 tmp_ */
data_ = sas_analysisdata
,/* 2. Input required Response variable or variables E.G: y or y1 y2 */
respi = y
,/* 3. Pre-Screening predictors using:GLMSELECT E.G: blank when performing model selection */
GLMSELECT =
,/* 4. Input optional class terms ? E.G: trt time sub */
class = c1 c2 c3
,/* 5. Input ith analysis (a counter) to attach to the saved output file name? E.G: _3 */
z = _3
,/* 6. Optional model statement options E.G: blank */
MODOPT=
,/* 7. Input must have fixed effects - in mixed model E.G. trt time trt*time */
must = x1 x2 x5 x10 x13 x9 x17 c1 c2 c3 x1*c1 x2*c2
,/* 8. Input list of class (line1) and continuous effects (line2) E.G: line1: blank Line2: x1 x5 x6 x8 x10 x12 x14 x15 */
fixed1 = c1 c2 c3
, fixed2 = x1 x2 x5 x10 x9 x13 x17
,/* 9. Input optional Random statement E.G: blank in this step */
Random =
,/* 10. Input Repeated statement E.G: Repeated time /sub=sub type=ar(1) */
Repeat = Repeated time /sub=sub type=ar(1)
,/* 11. Input Subject variable E.G: sub */
sub =
,/* 12. covariance structure(s) screening E.G: blank completed in previous step */
covari=
,/* 13. Exploration: Interaction and Quadratic plots E.G. blank needed in next step */
explor =
,/* 14. Display or save the Graphs/output? choose one E.G: word web pdf txt */
graph = web
,/* 15. Folder containing the PC data files? E.G: D:\allmixed\sasdata\ */
output = &wd
,/* 16. optional LSMEANS statement final model E.G: blank used in final step */
lsmeans =
,/* 17. Folder to save the output/graphics E.G: D:\allmixed\ */
dir2 = &wd
,/* 18. Optional model selection Start number of terms E.G: 3 */
start = 2
,/* 19. Optional model selection stop number of terms E.G: 4 */
Stop = 3
)
In the above of my testing codes, it is necessary to assign empty value for the Repeat macro variable, i.e., replacing 'Repeat = Repeated time /sub=sub type=ar(1)' with 'Repeat=', as there is no time variable in the input sas dataset.
After correcting the above error, the ALLMixed macro can run successfully with SAS 9.4 of Windows system.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.