|
Hello,
I have a data set with four blood pressure (BP) tests at week one thru week four on each record for each individual in the study. Some individuals who dropped out of the study have fewer BP tests, with the missing tests set to system missing. Every individual has a test score at week 1. I want to create a varibale that retains the value of the last non-system missing test. I tried the following code and it appears to work when the test for week four is valid or missing (it replaces the week 4 value with week 3) but fails when both weeks 3 and 4 are missing. Can anyone explain to me why this code fails? compute bplast=bpweek4. do if sysmis(bpweek4). compute bplast=bpweek3. else if sysmis(bpweek3). compute bplast=bpweek2. else if sysmis(bpweek2). compute bplast=bpweek1. end if. Thanks Gordon |
|
If the first condition is met, no other conditions are evaluated. So if pbweek4 is sysmis, bplast is set to bpweek3 and processing for that case is complete.
-----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Gordon Sent: Wednesday, May 02, 2007 6:32 AM To: [hidden email] Subject: do if Hello, I have a data set with four blood pressure (BP) tests at week one thru week four on each record for each individual in the study. Some individuals who dropped out of the study have fewer BP tests, with the missing tests set to system missing. Every individual has a test score at week 1. I want to create a varibale that retains the value of the last non-system missing test. I tried the following code and it appears to work when the test for week four is valid or missing (it replaces the week 4 value with week 3) but fails when both weeks 3 and 4 are missing. Can anyone explain to me why this code fails? compute bplast=bpweek4. do if sysmis(bpweek4). compute bplast=bpweek3. else if sysmis(bpweek3). compute bplast=bpweek2. else if sysmis(bpweek2). compute bplast=bpweek1. end if. Thanks Gordon |
|
In reply to this post by Gordon-33
At 07:31 AM 5/2/2007, Gordon wrote:
>I have a data set with four blood pressure (BP) tests at week one thru >week four for each individual. Some individuals have fewer BP tests, >with the missing tests set to system missing. I want to create a >variable that retains the value of the last non-system missing test. > >Can anyone explain to me why this code fails? it appears to work when >the test for week four is valid or missing (it replaces the week 4 >value with week 3) but fails when both weeks 3 and 4 are missing. > >compute bplast=bpweek4. >do if sysmis(bpweek4). > compute bplast=bpweek3. > else if sysmis(bpweek3). > compute bplast=bpweek2. > else if sysmis(bpweek2). > compute bplast=bpweek1. >end if. If 'bpweek4' is missing, you get the 'bpweek3' value; but that terminates the "DO IF", and nothing else is tested, whether 'bpweek3' is missing or not. You need to test for values that are not missing, rather than for those that are. Not tested, but like this: DO IF NOT sysmis(bpweek4). . COMPUTE bplast = bpweek4. ELSE IF NOT sysmis(bpweek3). . COMPUTE bplast = bpweek3. ELSE IF NOT sysmis(bpweek2). . COMPUTE bplast = bpweek2. ELSE IF NOT sysmis(bpweek1). . COMPUTE bplast = bpweek1. END IF. By the way, if you ever have a very long series of measurements like this, you can find the last valid one with VECTOR and LOOP, rather than needing ELSE IF clauses for every measurement. |
|
Alternatively, use IF instead of DO IF.
compute bplast=bpweek4. do repeat x=bpweek3,bpweek2,bpweek1. if sysmis(bplast) bplast=x. end repeat. The Do Repeat loop generates three IF statements. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Richard Ristow Sent: Wednesday, May 02, 2007 9:34 AM To: [hidden email] Subject: [BULK] Re: do if Importance: Low At 07:31 AM 5/2/2007, Gordon wrote: >I have a data set with four blood pressure (BP) tests at week one thru >week four for each individual. Some individuals have fewer BP tests, >with the missing tests set to system missing. I want to create a >variable that retains the value of the last non-system missing test. > >Can anyone explain to me why this code fails? it appears to work when >the test for week four is valid or missing (it replaces the week 4 >value with week 3) but fails when both weeks 3 and 4 are missing. > >compute bplast=bpweek4. >do if sysmis(bpweek4). > compute bplast=bpweek3. > else if sysmis(bpweek3). > compute bplast=bpweek2. > else if sysmis(bpweek2). > compute bplast=bpweek1. >end if. If 'bpweek4' is missing, you get the 'bpweek3' value; but that terminates the "DO IF", and nothing else is tested, whether 'bpweek3' is missing or not. You need to test for values that are not missing, rather than for those that are. Not tested, but like this: DO IF NOT sysmis(bpweek4). . COMPUTE bplast = bpweek4. ELSE IF NOT sysmis(bpweek3). . COMPUTE bplast = bpweek3. ELSE IF NOT sysmis(bpweek2). . COMPUTE bplast = bpweek2. ELSE IF NOT sysmis(bpweek1). . COMPUTE bplast = bpweek1. END IF. By the way, if you ever have a very long series of measurements like this, you can find the last valid one with VECTOR and LOOP, rather than needing ELSE IF clauses for every measurement. |
|
At 11:06 AM 5/2/2007, Oliver, Richard wrote:
>Alternatively, use IF instead of DO IF. > >compute bplast=bpweek4. >do repeat x=bpweek3,bpweek2,bpweek1. >. if sysmis(bplast) bplast=x. >end repeat. > >The Do Repeat loop generates three IF statements. Nice one! Richard |
| Free forum by Nabble | Edit this page |
