I'm having an issue squaring my X variable to create a new variable... I don't know where to place this transformation statement, or exactly what it should be. Here is my best guess so far, but it keeps telling me "Variable X2 is not found."
Changing a LABEL in PROC CONTENTS does not create a new variable X2 nor does it assign new values to the variable. If a given observation had a value of 4, after your PROC CONTENTS it sill has a value of 4, not 16. This is all easily viewed in your data set, you could see that for yourself by simply looking at work.import1 after PROC CONTENTS.
You need a SAS data step to compute a variable that has new values.
data import2;
set import1;
x2=x**2;
run;
An even simpler approach is to NOT explicitly compute x**2 by yourself prior to the regression, and to use PROC GLM for the regression, which will compute x**2 internally in the procedure.
proc glm data=import1;
model y = x x*x;
run;
quit;
@PaigeMiller (or anyone)
I "feel" that squaring of an independent variable MUST be done INSIDE the model statement.
Of course, Statistics is not about feelings, but is my intuition correct?
Or can it be done either way: Inside or outside?
As far as I know, either way works and should give the same answer (if done properly). Easy enough for you to test.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.