The script first generates a 'Polynomial' dataset based on a polynomial function. Then, it uses PROC ORTHOREG to fit a 9th-degree polynomial model. The model results are stored and used by PROC PLM to score the zeros of the original function. Concurrently, PROC GLM is used to fit a similar model, and predictions are also calculated with PROC PLM. Finally, the predictions from both models (ORTHOREG and GLM) are merged and displayed for comparison.
Data Analysis
Type : INTERNAL_CREATION
The script creates two datasets: 'Polynomial' and 'Zeros'. The data is entirely generated via 'do' loops in DATA steps, without relying on external sources.
1 Code Block
DATA STEP Data
Explanation : This block creates the 'Polynomial' table. It generates 101 observations by calculating 'x' and 'y' values according to a polynomial function, without using input data.
Copied!
title 'Polynomial Data';
data Polynomial;
do i = 1 to 101;
x = (i-1)/(101-1);
y = 10**(9/2);
do j = 0 to 8;
y = y * (x - j/8);
end;
output;
end;
run;
1
title 'Polynomial Data';
2
DATA Polynomial;
3
DO i = 1 to 101;
4
x = (i-1)/(101-1);
5
y = 10**(9/2);
6
DO j = 0 to 8;
7
y = y * (x - j/8);
8
END;
9
OUTPUT;
10
END;
11
RUN;
2 Code Block
PROC ORTHOREG
Explanation : This block uses the ORTHOREG procedure to perform a 9th-degree polynomial regression on the 'y' variable as a function of 'x'. The model is stored in the 'OStore' object and a plot of the fitted model is produced.
Copied!
ods graphics on;
proc orthoreg data=Polynomial;
effect xMod = polynomial(x / degree=9);
model y = xMod;
effectplot fit / obs;
store OStore;
run;
ods graphics off;
1
ods graphics on;
2
3
PROC ORTHOREGDATA=Polynomial;
4
effect xMod = polynomial(x / degree=9);
5
model y = xMod;
6
effectplot fit / obs;
7
store OStore;
8
RUN;
9
10
ods graphics off;
3 Code Block
DATA STEP Data
Explanation : This block creates the 'Zeros' table which contains the roots (zeros) of the polynomial function used to generate the initial data. These 'x' values will be used for prediction.
Copied!
data Zeros(keep=x);
do j = 0 to 8;
x = j/8;
output;
end;
run;
1
DATA Zeros(keep=x);
2
DO j = 0 to 8;
3
x = j/8;
4
OUTPUT;
5
END;
6
RUN;
4 Code Block
PROC PLM
Explanation : This procedure uses the 'OStore' model (created by PROC ORTHOREG) to calculate predicted values ('OPred') for each observation in the 'Zeros' table. The results are saved in the 'OZeros' table.
Explanation : Displays the content of the last created table, which is 'OZeros', showing the predictions from the ORTHOREG model.
Copied!
proc print noobs;
run;
1
PROC PRINT noobs;
2
RUN;
6 Code Block
PROC GLM
Explanation : This block uses the GLM (General Linear Model) procedure to fit a 9th-degree polynomial model (specified by successive interactions of 'x'). The model is stored in 'GStore' for later use.
Copied!
proc glm data=Polynomial;
model y = x|x|x|x|x|x|x|x|x;
store GStore;
run;
1
PROC GLMDATA=Polynomial;
2
model y = x|x|x|x|x|x|x|x|x;
3
store GStore;
4
RUN;
7 Code Block
PROC PLM
Explanation : Similar to the previous step, this procedure uses the 'GStore' model (created by PROC GLM) to calculate predictions ('GPred') for the 'Zeros' table. The results are stored in the 'GZeros' table.
Explanation : This block merges the 'OZeros' and 'GZeros' tables to create a new 'Zeros' table that contains the predictions from both models (ORTHOREG and GLM) side-by-side for easy comparison.
Copied!
data Zeros;
merge OZeros GZeros;
run;
1
DATA Zeros;
2
MERGE OZeros GZeros;
3
RUN;
9 Code Block
PROC PRINT
Explanation : Displays the content of the final 'Zeros' table, which compares the predicted values from the ORTHOREG model ('OPred') and the GLM model ('GPred').
Copied!
proc print noobs;
run;
1
PROC PRINT noobs;
2
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.