Published on :
Général EXTERNE

Sans titre

This code is also available in: Deutsch Español Français
Awaiting validation
Data Analysis

Type : EXTERNE


Data is entirely imported from external CSV files ('SouthernTemp.csv', 'SouthernTemp1e.csv', 'SouthernTempBON.csv') via `FILENAME` statements and the `PROC IMPORT` procedure.

1 Code Block
PROC IMPORT Data
Explanation :
This block prepares the environment by deleting the temporary table `WORK.stemp` if it exists. It then defines a `FILENAME` to point to the 'SouthernTemp.csv' CSV file, and imports the data from this file into a new SAS table named `WORK.stemp`. The `GETNAMES=YES` option indicates that the first line of the CSV contains the variable names. `PROC CONTENTS` is used to display the metadata of the created table, and `%web_open_table` opens the table in the SAS Studio interface.
Copied!
1%web_drop_table(WORK.stemp);
2 
3FILENAME REFFILE '/home/gsturrock0/STAT2/SouthernTemp.csv';
4 
5PROC IMPORT DATAFILE=REFFILE
6 DBMS=CSV
7 OUT=WORK.stemp;
8 GETNAMES=YES;
9RUN;
10 
11PROC CONTENTS DATA=WORK.stemp; RUN;
12 
13%web_open_table(WORK.stemp);
2 Code Block
PROC IMPORT Data
Explanation :
Similar to the previous block, this block deletes the `WORK.pstemp` table if it exists, then imports data from another CSV file, 'SouthernTemp1e.csv', into the SAS table `WORK.pstemp`. `PROC CONTENTS` displays the metadata and `%web_open_table` opens the table in SAS Studio.
Copied!
1%web_drop_table(WORK.pstemp);
2 
3FILENAME REFFILE '/home/gsturrock0/STAT2/SouthernTemp1e.csv';
4 
5PROC IMPORT DATAFILE=REFFILE
6 DBMS=CSV
7 OUT=WORK.pstemp;
8 GETNAMES=YES;
9RUN;
10 
11PROC CONTENTS DATA=WORK.pstemp; RUN;
12 
13%web_open_table(WORK.pstemp);
3 Code Block
PROC SGPLOT
Explanation :
This block uses `PROC SGPLOT` to generate a graph from the `stemp` table data. It superimposes a series plot (`series`) showing the evolution of `temperature` relative to `year`, and a scatter plot (`scatter`) of the same variables to visualize individual data points.
Copied!
1*AQ1.a
2proc sgplot data=stemp;
3series x=year y=temperature;
4scatter x=year y=temperature;
5RUN;
4 Code Block
PROC GLM
Explanation :
This block performs a linear regression analysis using `PROC GLM`. The model specifies that the `temperature` variable is predicted by the `year` variable from the `stemp` table data. The `plots=all` option requests the generation of all standard diagnostic plots for model evaluation.
Copied!
1*AQ1.b and .c;
2 
3PROC GLM DATA=stemp plots=all;
4model temperature = year;
5RUN;
5 Code Block
PROC AUTOREG
Explanation :
This block uses `PROC AUTOREG` for an autoregressive regression analysis on the `stemp` table. The model predicts `temperature` as a function of `year`. The `/ dwprob` option requests the calculation of the Durbin-Watson test to detect autocorrelation in the residuals. `plots=all` generates the diagnostic plots.
Copied!
1*AQ1.d;
2PROC AUTOREG DATA=stemp plots=all;
3model temperature = year / dwprob;
4RUN;
6 Code Block
PROC AUTOREG Data
Explanation :
This block executes an autoregressive regression on the `pstemp` table with `PROC AUTOREG`. The model includes `temperature` as the dependent variable and `year` as the predictor. The `nlag=1` option specifies a lag of order 1 for modeling autocorrelation. The `output` statement creates a new table `fcast` containing the predicted values (`yhat`), mean forecasts (`ytrend`), and the lower (`lower`) and upper (`upper`) confidence limits.
Copied!
1*AQ1.e and .f;
2PROC AUTOREG DATA=pstemp plots=all;
3model temperature = year / nlag=1 dwprob;
4OUTPUT out=fcast p=yhat pm=ytrend lcl=lower ucl=upper;
5RUN;
7 Code Block
PROC SGPLOT
Explanation :
This block uses `PROC SGPLOT` to visualize the forecast results stored in the `fcast` table. It displays a main title and a subtitle, then draws a band (`band`) representing the forecast confidence intervals (`lower`, `upper`). Actual temperatures (`temperature`) are shown as a scatter plot and a series, and the mean forecast series (`ytrend`) is added for comparison.
Copied!
1PROC SGPLOT DATA=fcast;
2title 'Southern Hemisphere Temperature Comparison to 161 Year Mean';
3title2 'with 2011 Forecast';
4band x=year upper=upper lower=lower;
5scatter x=Year y=temperature;
6series x=year y=temperature;
7series x=year y=ytrend / lineattrs=(color=black);
8RUN;
9title;
10title2;
8 Code Block
PROC IMPORT Data
Explanation :
This bonus section performs a similar operation to the previous import blocks. It deletes the `WORK.sbonus` table if it exists, then imports data from the 'SouthernTempBON.csv' CSV file into a new SAS table named `WORK.sbonus`. Metadata is displayed via `PROC CONTENTS`, and the table is opened in SAS Studio.
Copied!
1*bonus;
2%web_drop_table(WORK.sbonus);
3 
4 
5FILENAME REFFILE '/home/gsturrock0/STAT2/SouthernTempBON.csv';
6 
7PROC IMPORT DATAFILE=REFFILE
8 DBMS=CSV
9 OUT=WORK.sbonus;
10 GETNAMES=YES;
11RUN;
12 
13PROC CONTENTS DATA=WORK.sbonus; RUN;
14 
15 
16%web_open_table(WORK.sbonus);
9 Code Block
PROC AUTOREG
Explanation :
This bonus block executes an autoregressive regression on the `sbonus` table using `PROC AUTOREG`. The model includes the dependent variable `temperature` and the predictors `year` and `recent`. The `recent` variable is declared as a categorical variable (`class`). `nlag=1` and `dwprob` are used for autocorrelation and the Durbin-Watson test. The `output` statement is commented out, meaning no new forecast table is generated by this block.
Copied!
1PROC AUTOREG DATA=sbonus plots=all;
2class recent;
3model temperature = year recent / nlag=1 dwprob;
4*output out=fcast p=yhat pm=ytrend lcl=lower ucl=upper;
5RUN;
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.