Posted by
David Marso on
Oct 17, 2012; 4:27pm
URL: http://spssx-discussion.165.s1.nabble.com/Do-repeat-extraction-conversion-issue-tp5715692p5715697.html
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.
....
--
Maguin, Eugene wrote
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
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?"