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.
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.
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.
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!
*AQ1.b and .c;
proc glm data=stemp plots=all;
model temperature = year;
run;
1
*AQ1.b and .c;
2
3
PROC GLMDATA=stemp plots=all;
4
model temperature = year;
5
RUN;
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!
*AQ1.d;
proc autoreg data=stemp plots=all;
model temperature = year / dwprob;
run;
1
*AQ1.d;
2
PROC AUTOREGDATA=stemp plots=all;
3
model temperature = year / dwprob;
4
RUN;
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!
*AQ1.e and .f;
proc autoreg data=pstemp plots=all;
model temperature = year / nlag=1 dwprob;
output out=fcast p=yhat pm=ytrend lcl=lower ucl=upper;
run;
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!
proc sgplot data=fcast;
title 'Southern Hemisphere Temperature Comparison to 161 Year Mean';
title2 'with 2011 Forecast';
band x=year upper=upper lower=lower;
scatter x=Year y=temperature;
series x=year y=temperature;
series x=year y=ytrend / lineattrs=(color=black);
run;
title;
title2;
1
PROC SGPLOTDATA=fcast;
2
title 'Southern Hemisphere Temperature Comparison to 161 Year Mean';
3
title2 'with 2011 Forecast';
4
band x=year upper=upper lower=lower;
5
scatter x=Year y=temperature;
6
series x=year y=temperature;
7
series x=year y=ytrend / lineattrs=(color=black);
8
RUN;
9
title;
10
title2;
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.
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!
proc autoreg data=sbonus plots=all;
class recent;
model temperature = year recent / nlag=1 dwprob;
*output out=fcast p=yhat pm=ytrend lcl=lower ucl=upper;
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.
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.