Programming the statistical procedures from SAS

How can I assign groups to observations with if else statements? Possible Alternative?

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

How can I assign groups to observations with if else statements? Possible Alternative?

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.


Accepted Solutions
Solution
‎03-23-2012 07:17 PM
Respected Advisor
Posts: 4,606

How can I assign groups to observations with if else statements? Possible Alternative?

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


All Replies
Solution
‎03-23-2012 07:17 PM
Respected Advisor
Posts: 4,606

How can I assign groups to observations with if else statements? Possible Alternative?

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
New Contributor
Posts: 2

How can I assign groups to observations with if else statements? Possible Alternative?

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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