SAS Programming

DATA Step, Macro, Functions and more
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

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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