|
I have vars d1 to d85. I want to scan them for the first instance of a
missing value and set a new variable to that integer number. For example, if d32 was the first variable with a missing value for that case, firstmiss = 32. I have tinkered with loop and do repeat syntax but have been unsuccessful. Suggestions? -- Larry W. Hawk, Jr., Ph.D. Associate Professor of Psychology Park Hall, Box 604110 The University of Buffalo, SUNY Buffalo, NY 14260-4110 Phone: 716-645-3650 x231 Fax: 716-645-3801 E-mail: [hidden email] |
|
At 05:28 PM 8/29/2007, Larry Hawk wrote:
>I have vars d1 to d85. I want to scan them for the first instance of >a missing value and set a new variable to that integer number. For >example, if d32 was the first variable with a missing value for that >case, firstmiss = 32. I have tinkered with loop and do repeat syntax >but have been unsuccessful. Either LOOP or DO REPEAT should work. Here's a LOOP solution, though not tested: NUMERIC firstmiss (F4). VECTOR D_var=d1 TO d85. LOOP #I = 1 TO 85. . IF MISSING(D_var(#I)) firstmiss = #I. END LOOP IF NOT MISSING(firstmiss). |
|
In reply to this post by Larry Hawk
Thanks, Dan! This was perfect! Thanks also to Richard Ristow, who also
responded. Daniel E WILLIAMS wrote: > Try this: > > DATA LIST FREE / d1 d2 d3 d4 d5. > BEGIN DATA > 1,,3,4,5, 1,2,3,,5, 1,2,3,4,5, 1,,3,,5 > END DATA. > > COMPUTE first_missing = $SYSMIS. > EXECUTE. > > VECTOR D=D1 TO D5. > LOOP #I=1 TO 5. > + IF MISSING(D(#I)) AND MISSING(first_missing) first_missing = #I. > END LOOP. > EXECUTE. > The value of first_missing retains a missing value if there are no > missing values in d1 through d5. If there are more than one missing > value, first_missing is set to the first of them. I hope this helps! > > > > Dan Williams > Forecasting, Research and Analysis Office > Department of Human Services > State of Oregon, USA > 503 947 5354 > > >>> "Larry Hawk" <[hidden email]> 8/29/2007 2:28:50 PM >>> > I have vars d1 to d85. I want to scan them for the first instance of a > missing value and set a new variable to that integer number. For > example, if d32 was the first variable with a missing value for that > case, firstmiss = 32. I have tinkered with loop and do repeat syntax > but have been unsuccessful. Suggestions? > > -- > > Larry W. Hawk, Jr., Ph.D. > Associate Professor of Psychology > Park Hall, Box 604110 > The University of Buffalo, SUNY > Buffalo, NY 14260-4110 > Phone: 716-645-3650 x231 > Fax: 716-645-3801 > E-mail: [hidden email] > -- -- Larry W. Hawk, Jr., Ph.D. Associate Professor of Psychology 231 Park Hall, Box 604110 The University of Buffalo, SUNY Buffalo, NY 14260-4110 Phone: 716-645-3650 x231 Fax: 716-645-3801 E-mail: [hidden email] |
|
In reply to this post by Larry Hawk
-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Larry Hawk Sent: Wednesday, August 29, 2007 4:29 PM To: [hidden email] Subject: simplifying syntax I have vars d1 to d85. I want to scan them for the first instance of a missing value and set a new variable to that integer number. For example, if d32 was the first variable with a missing value for that case, firstmiss = 32. I have tinkered with loop and do repeat syntax but have been unsuccessful. Suggestions? ----------------- Vector d = d1 to d85. Loop firstmissing = 1 to 85. Do if (missing(d(firstmissing))). break. End if. End loop. execute. Firstmissing will have the value 86 if the row contains no missing values. Jonathan Fry SPSS Inc. |
|
At 08:53 PM 8/29/2007, Fry, Jonathan B. wrote:
>Vector d = d1 to d85. >Loop firstmissing = 1 to 85. > Do if (missing(d(firstmissing))). > break. > End if. >End loop. Cute! Not needing a separate loop counter. >Firstmissing will have the value 86 if the row contains no missing >values. So, probably, follow by RECODE firstmissing (86=SYSMIS). |
| Free forum by Nabble | Edit this page |
