BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASstudent2013
Calcite | Level 5

Hello,

I need to perform a two-way ANOVA by age group and sex with no interaction term, and then with an interaction term.

When I do this, it's not recognizing the 'agegrp' variable, even though I created it earlier! Included below is the code (also includes histogram and qqplot generation) and then a portion of the log. Do you know why it is not recognizing the 'agegrp' variable in the end for the 2-way ANOVA?

Any and all help is much appreciated!!


data test;

set homewrk2.test;

/*create new variable for age*/

age=int((dov-dob)/365.25);

run;

data test;

set homewrk2.test;

/*create age groups so that group 1 = children under 12 years old, group 2 = children 12 or older but younger than 20, group 3 = 20 or older*/

if age < 12 then agegrp=1;

else if 12 <= age < 20 then agegrp=2;

else if age >=20 then agegrp=3;

run;

title 'Distribution of periosteal circumference';

ods graphics off;

ods select Lognormal.ParameterEstimates Lognormal.GoodnessOfFit MyPlot;

/*Create a histogram for the variable periosteal circumference to test for normality*/

proc univariate data=homewrk2.test;

   var peri;

   histogram / lognormal(w=3 theta=est)

               vaxis = axis1

               name  = 'MyPlot';

   inset n mean (5.3) std='Std Dev' (5.3) skewness (5.3) /

         pos = ne  header = 'Summary Statistics';

   axis1 label=(a=90 r=0);

run;

/*Create a qqplot for the variable periosteal circumference to test for normality*/

title ’Normal Quantile-Quantile Plot for Periosteal Circumference’;

proc capability data=homewrk2.test noprint;

spec lsl=9.5 llsl=2 clsl=blue

usl=10.5 lusl=20 cusl=blue;

qqplot peri / normal(mu=est sigma=est color=red l=2)

square

nospeclegend;

run;

/*Two way ANOVA by age group and sex with no interaction term. Save the predicted values into a data set called out1*/

proc glm data=homewrk2.test;

class sex agegrp;

model peri = sex agegrp;

run;

LOG:


216  proc glm data=homewrk2.test;

217  class sex age;

ERROR: Variable AGE not found.

NOTE: The previous statement has been deleted.

218  model peri = sex age;

ERROR: Variable age not found.

NOTE: The previous statement has been deleted.

219  run;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You're not referencing your datasets properly.

*Dataset TEST was created in work library;

data test;

set homewrk2.test;

/*create new variable for age*/

age=int((dov-dob)/365.25);

run;


*Replace dataset TEST in work library using the test dataset from library homewrk2 instead of work;

data test;

set homewrk2.test;

/*create age groups so that group 1 = children under 12 years old, group 2 = children 12 or older but younger than 20, group 3 = 20 or older*/

if age < 12 then agegrp=1;

else if 12 <= age < 20 then agegrp=2;

else if age >=20 then agegrp=3;

run;


You should open your datasets or print them to make sure it's doing what you want.


You can correct this by using doing one datastep instead. Also, make sure in further code you refer to test rather than homework.test because they're two different datasets.


data test;

set homewrk2.test;

/*create age groups so that group 1 = children under 12 years old, group 2 = children 12 or older but younger than 20, group 3 = 20 or older*/

age=int((dov-dob)/365.25);

if age < 12 then agegrp=1;

else if 12 <= age < 20 then agegrp=2;

else if age >=20 then agegrp=3;

run;

View solution in original post

2 REPLIES 2
Reeza
Super User

You're not referencing your datasets properly.

*Dataset TEST was created in work library;

data test;

set homewrk2.test;

/*create new variable for age*/

age=int((dov-dob)/365.25);

run;


*Replace dataset TEST in work library using the test dataset from library homewrk2 instead of work;

data test;

set homewrk2.test;

/*create age groups so that group 1 = children under 12 years old, group 2 = children 12 or older but younger than 20, group 3 = 20 or older*/

if age < 12 then agegrp=1;

else if 12 <= age < 20 then agegrp=2;

else if age >=20 then agegrp=3;

run;


You should open your datasets or print them to make sure it's doing what you want.


You can correct this by using doing one datastep instead. Also, make sure in further code you refer to test rather than homework.test because they're two different datasets.


data test;

set homewrk2.test;

/*create age groups so that group 1 = children under 12 years old, group 2 = children 12 or older but younger than 20, group 3 = 20 or older*/

age=int((dov-dob)/365.25);

if age < 12 then agegrp=1;

else if 12 <= age < 20 then agegrp=2;

else if age >=20 then agegrp=3;

run;

SASstudent2013
Calcite | Level 5

Thank you. This works. I am also opening the dataset along the way to be sure that everything is working correctly.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 843 views
  • 0 likes
  • 2 in conversation