BookmarkSubscribeRSS Feed
mpiotro2
Calcite | Level 5

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

 

HW4 - Code.PNGHW 4 - Error Log.PNG

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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
MelissaM
Obsidian | Level 7

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

PaigeMiller
Diamond | Level 26

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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 30093 views
  • 3 likes
  • 3 in conversation