Published on :
Statistic CREATION_INTERNE

Correlation and Regression Analysis on Socio-Economic Data

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by creating a `SocEcon` table containing five socio-economic variables via a DATA step. It then proceeds to calculate a correlation matrix with `PROC CORR`. A second CORR type table is also created manually. The core of the analysis relies on `PROC REG`, which is used twice: first to fit two regression models and save their estimates and covariances (`OUTEST=regest COVOUT`), then to generate the matrix of sums of squares and cross products (`OUTSSCP=regsscp`). The intermediate result tables (`corrcorr`, `datacorr`, `regest`, `regsscp`) are displayed with `PROC PRINT` for inspection.
Data Analysis

Type : CREATION_INTERNE


The two data tables used, `SocEcon` and `datacorr`, are created within the script using the `datalines` instruction. No external data source is necessary.

1 Code Block
DATA STEP Data
Explanation :
This DATA STEP block creates the `SocEcon` working table. It reads 12 observations for 5 socio-economic variables (Pop, School, Employ, Services, House) directly from the code using the `datalines` instruction.
Copied!
1title 'Five Socioeconomic Variables';
2title2 'Harman (1976), Modern Factor Analysis, Third Edition';
3 
4DATA SocEcon;
5 INPUT Pop School Employ Services House;
6 DATALINES;
75700 12.8 2500 270 25000
81000 10.9 600 10 10000
93400 8.8 1000 10 9000
103800 13.6 1700 140 25000
114000 12.8 1600 140 25000
128200 8.3 2600 60 12000
131200 11.4 400 10 16000
149100 11.5 3300 60 14000
159900 12.5 3400 180 18000
169600 13.7 3600 390 25000
179600 9.6 3300 80 12000
189400 11.4 4000 100 13000
19;
20 
2 Code Block
PROC CORR Data
Explanation :
`PROC CORR` procedure calculates the correlation matrix for all numeric variables in the `SocEcon` table. The `noprint` option suppresses display in the standard output, and `out=corrcorr` saves the results in a new table named `corrcorr`. This table is then displayed with `PROC PRINT` and its structure is inspected with `PROC CONTENTS`.
Copied!
1PROC CORR noprint out=corrcorr;
2RUN;
3 
4PROC PRINT DATA=corrcorr;
5RUN;
6 
7PROC CONTENTS DATA=corrcorr;
8RUN;
3 Code Block
DATA STEP Data
Explanation :
This DATA STEP manually creates a special SAS CORR type table named `datacorr`. This table type can be used as input by other statistical procedures. The correlation matrix data is read from the `datalines`. The resulting table is displayed with `PROC PRINT`.
Copied!
1title 'Five Socioeconomic Variables';
2 
3DATA datacorr(type=corr);
4 INFILE CARDS missover;
5 _type_='corr';
6 INPUT _Name_ $ Pop School Employ Services House;
7 DATALINES;
8Pop 1.00000
9School 0.00975 1.00000
10Employ 0.97245 0.15428 1.00000
11Services 0.43887 0.69141 0.51472 1.00000
12House 0.02241 0.86307 0.12193 0.77765 1.00000
13;
14 
15PROC PRINT DATA=datacorr;
16RUN;
4 Code Block
PROC REG Data
Explanation :
This `PROC REG` procedure performs two linear regression analyses on the `SocEcon` table. The results (parameter estimates) are stored in the `regest` table using `outest=regest`. The `covout` option includes the covariance matrix of the estimates. Both models, 'full' and 'empser', are specified. The `regest` result table is then printed.
Copied!
1PROC REG DATA=SocEcon outest=regest covout;
2 full: model house=pop school employ services / noprint;
3 empser: model house=employ services / noprint;
4QUIT;
5 
6PROC PRINT DATA=regest;
7RUN;
5 Code Block
PROC REG Data
Explanation :
A second execution of `PROC REG` is used to generate the matrix of sums of squares and cross products (SSCP) for the model variables. The result is stored in the `regsscp` table via the `outsscp=regsscp` option. The `regsscp` table is then displayed for verification.
Copied!
1PROC REG DATA=SocEcon outsscp=regsscp;
2 model house=pop school employ services / noprint;
3QUIT;
4 
5PROC PRINT DATA=regsscp;
6RUN;
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.