I'm having what seems to be an incorrect problem with the following syntax.
STRING SCALE(A16). DO REPEAT A='FunctImpairment' 'Symptoms' 'SymptomsB' 'KidStrength' 'FamStrength' 'FamProb'/B=15 8 9 11 11 7. + DO IF (SUBSTR(IV,1,B) EQ A). + COMPUTE SCALE=SUBSTR(IV,1,B). + COMPUTE ITEM=NUMBER(RTRIM(SUBSTR(IV,B+1,2),' '),F2.0). + END IF. END REPEAT. EXECUTE. FORMAT ITEM(F2.0). The data going into/coming out (of) this do repeat are (there are multiple records for each example IV value and the range for Item is between 1 and 30) IV Scale Item FunctImpairment1 FunctImpairment 1 Symptoms1 Symptoms 1 SymptomsB27 SymptomsB 27 KidStrength1 KidStrength 1 FamStrength1 FamStrength 1 FamProb1 FamProb 1 I get this warning >Warning # 1102 >An invalid numeric field has been found. The result has been set to the >system-missing value. >Command line: 306 Current case: 195 Current splitfile group: 1 >Field contents: 'B2' I understand what it means and I should see a sysmis value for Item for case 195. I do not however. I see the correct value: 27. It seems like I should not have gotten the warning and, having gotten the warning, I should be seeing Item = sysmis for the indicated cases. Am I misunderstanding something (or is there a program issue)? Gene Maguin ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Administrator
|
Easy Gene,
It locates Symptoms in "SymptomsB27" and then attempts to convert "B2" to a number ;-) You could do something like the following. COMPUTE #found=0. STRING SCALE(A16). DO REPEAT A='FunctImpairment' 'SymptomsB' 'Symptoms' 'KidStrength' 'FamStrength' 'FamProb' /B=15 9 8 11 11 7. DO IF NOT(#found). + DO IF (SUBSTR(IV,1,B) EQ A). + COMPUTE SCALE=SUBSTR(IV,1,B). + COMPUTE ITEM=NUMBER(RTRIM(SUBSTR(IV,B+1,2),' '),F2.0). + COMPUTE #found=1. + END IF. END IF. END REPEAT. EXECUTE. ---- OTOH: I would make it simpler and delete the second list and use LENGTH(A) instead of B in the SUBSTR also possibly to appease the Unicode fans use CHAR.LENGTH and CHAR.SUBSTR versions. DO REPEAT A='FunctImpairment' 'SymptomsB' 'Symptoms' 'KidStrength' 'FamStrength' 'FamProb'. DO IF NOT(#found). + DO IF (CHAR.SUBSTR(IV,1,CHAR.LENGTH(A)) EQ A). + COMPUTE SCALE=CHAR.SUBSTR(IV,1,LENGTH(A)). + COMPUTE ITEM=NUMBER(RTRIM(CHAR.SUBSTR(IV,CHAR.LENGTH(A)+1,2),' '),F2.0). + COMPUTE #found=1. + END IF. END IF. END REPEAT. Do you have something against the INDEX function? It seems that would take much of the pain out of this? COMPUTE #found= INDEX(IV,A). DO IF #found GT 0. .... --
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
David,
I was writing a long winded, very detailed reply and I finally realized what was wrong (and for the 30,000th time the problem was my failure to work through how what I was coding worked, which I feared was the problem). The code segment: DO REPEAT A='FunctImpairment' 'Symptoms' 'SymptomsB' 'KidStrength' 'FamStrength' 'FamProb'/B=15 8 9 11 11 7. + DO IF (SUBSTR(IV,1,B) EQ A). + COMPUTE SCALE=SUBSTR(IV,1,B). + COMPUTE ITEM=NUMBER(RTRIM(SUBSTR(IV,B+1,2),' '),F2.0). + END IF. In the file IV takes on these values and takes them on in this order: 'FunctImpairment1' to 'FunctImpairment5' 'SymptomsB27' to 'SymptomsB30' 'Symptoms1' to 'Symptoms26' 'KidStrength1' to 'KidStrength12' 'FamStrength1' to 'FamStrength6' 'FamProb1' to 'FamProb14' For example, both 'Symptoms23' and 'SymptomsB29' will satisfy the test + DO IF (SUBSTR(IV,1,B) EQ A). Where A='Symptoms' . B=8, B+1=9, and SUBSTR(IV,9,2) will equal '23' for 'Symptoms23' but 'B2' for 'SymptomsB29' I'm satisfied. Thank you for your reply, it helped me eventually see what was wrong. Gene Maguin ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Administrator
|
Here is an easier way not fraught with the possible order issue and not requiring the #found flag.
Also won't need to be modified if you end up with other strings later. STRING SCALE (a20). COMPUTE #=CHAR.INDEX(IV,"0123456789",1). COMPUTE SCALE =CHAR.SUBSTR(IV,1,#-1). COMPUTE ITEM=NUMBER(CHAR.SUBSTR(IV,#,2),F2).
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Free forum by Nabble | Edit this page |