Calcite | Level 5

## How to square an independent variable

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."

3 REPLIES 3
Diamond | Level 26

## Re: How to square an independent variable

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;``` ```

--
Paige Miller
Obsidian | Level 7

## Re: How to square an independent variable

@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?

Diamond | Level 26

## Re: How to square an independent variable

As far as I know, either way works and should give the same answer (if done properly). Easy enough for you to test.

--
Paige Miller
Discussion stats
• 3 replies
• 30659 views
• 3 likes
• 3 in conversation