Login  Register

Re: Do repeat extraction conversion issue

Posted by David Marso on Oct 17, 2012; 6:39pm
URL: http://spssx-discussion.165.s1.nabble.com/Do-repeat-extraction-conversion-issue-tp5715692p5715700.html

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).

Maguin, Eugene wrote
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
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?"