The script begins by creating a 'SchoolSample' dataset. It simulates hierarchically structured data with 300 schools, each having 25 neighborhoods, and for each neighborhood, 2 observations at 4 different time points. The variables 'SchoolID', 'Neighborhood', 'bInt', 'bTime', 'bTime2' are generated. The dependent variable 'Math' is calculated with a random component. Then, PROC HPLMIXED is used to fit a linear mixed model to the data. The variables 'Neighborhood' and 'SchoolID' are declared as classification variables. The fixed model includes 'Time' and 'Time*Time'. Random effects include the intercept ('int'), 'Time', and 'Time*Time' nested within 'Neighborhood(SchoolID)', with an unstructured covariance structure (TYPE=UN).
Data Analysis
Type : CREATION_INTERNE
The 'SchoolSample' dataset is entirely created internally within the SAS script via a DATA step (DATA STEP). It does not use external data or default SAS libraries like SASHELP.
1 Code Block
DATA STEP Data
Explanation : This DATA STEP block generates the 'SchoolSample' dataset. It uses nested loops to create 300 schools, each with 25 neighborhoods, and for each neighborhood, 2 observations at 4 different time points ('Time'). The variables 'bInt', 'bTime', 'bTime2' are randomly generated to simulate fixed effects. The dependent variable 'Math' is then calculated as a quadratic function of time with the addition of random noise ('rannor'). The 'output;' statement writes each observation to the dataset.
Copied!
data SchoolSample;
do SchoolID = 1 to 300;
do nID = 1 to 25;
Neighborhood = (SchoolID-1)*5 + nId;
bInt = 5*ranuni(1);
bTime = 5*ranuni(1);
bTime2 = ranuni(1);
do sID = 1 to 2;
do Time = 1 to 4;
Math = bInt + bTime*Time + bTime2*Time*Time + rannor(2);
output;
end;
end;
end;
end;
run;
1
DATA SchoolSample;
2
DO SchoolID = 1 to 300;
3
DO nID = 1 to 25;
4
Neighborhood = (SchoolID-1)*5 + nId;
5
bInt = 5*ranuni(1);
6
bTime = 5*ranuni(1);
7
bTime2 = ranuni(1);
8
DO sID = 1 to 2;
9
DO Time = 1 to 4;
10
Math = bInt + bTime*Time + bTime2*Time*Time + rannor(2);
11
OUTPUT;
12
END;
13
END;
14
END;
15
END;
16
RUN;
2 Code Block
PROC HPLMIXED
Explanation : This block uses PROC HPLMIXED to fit a linear mixed model. The 'data=SchoolSample' option specifies the input dataset. The 'class' statement identifies 'Neighborhood' and 'SchoolID' as categorical variables. The 'model' statement defines the fixed effects structure, with 'Math' as the dependent variable and 'Time' and 'Time*Time' as predictors. The '/solution' option requests the display of fixed effects parameter estimates. The 'random' statement specifies the random effects: an intercept ('int'), 'Time', and 'Time*Time', which are nested within the 'Neighborhood(SchoolID)' unit. The 'type=un' option indicates an unstructured covariance matrix for the random effects.
Copied!
proc hplmixed data=SchoolSample;
class Neighborhood SchoolID;
model Math = Time Time*Time / solution;
random int Time Time*Time / sub=Neighborhood(SchoolID) type=un;
run;
1
PROC HPLMIXEDDATA=SchoolSample;
2
class Neighborhood SchoolID;
3
model Math = Time Time*Time / solution;
4
random int Time Time*Time / sub=Neighborhood(SchoolID) type=un;
5
RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : S A S S A M P L E L I B R A R Y
NAME: HPLMXGS
TITLE: Getting Started Example for PROC HPLMIXED
PRODUCT: STAT
SYSTEM: ALL
KEYS: Mixed Models, Analysis of Covariance
PROCS: HPLMIXED
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.