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

I have a data set of 200 observations, involving demographic variables (gender, age, income level etc) that I'm to test against some health related variables (blood pressure, cholesterol, glucose levels etc). I was thinking it'd be easier to manage if I was to use a class variable involving age, but in the file the data is to be read from, it gives all individual ages.

What I've attempted is some if else statements to sort of "create" a coding for age. I ran proc glm a few times, to compare against each health variable. The issue I'm having is that it seems to always assign agegroup to 1 when using it in a class statement, as can be seen in the code. It seems to me that it isn't running the if else construct for each observation.

My code can be found here. http://snipt.org/ugOi9

If you run it, and look in the class levels for each proc glm in the output, you can see that there's supposedly only one level for agegroup, and all are 1 which is where my issue is.

How can I fix my if else statements to properly assign agegroup to whichever the particular observation may fall in? If there's a more proper way to do this, what would that be?

Any input is greatly appreciated, thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

It is because of the order of statements in your datastep. Move the IF-ELSE statements after the input statement. You must read the data before you access its value. At the beginning of each datastep iteration, all variables, except those named in retain statements, take a missing value. And missing compares as inferior to any non missing number.

PG

PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

It is because of the order of statements in your datastep. Move the IF-ELSE statements after the input statement. You must read the data before you access its value. At the beginning of each datastep iteration, all variables, except those named in retain statements, take a missing value. And missing compares as inferior to any non missing number.

PG

PG
Zachary_Goltz
Calcite | Level 5

Wow, what a silly mistake for me to make. That makes perfect sense. Can't really modify an observation that doesn't exist yet.


Thank you very much.

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

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1123 views
  • 0 likes
  • 2 in conversation