Split Parameter

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Split Parameter

Simon Levin
Hi Richard,

Thank you for your response. I’m sorry I didn't make myself clear last
time.

Here is an example of a program that takes names from a given input list
and creates names for new variables from their parts. I need to improve it
a little.

DEFINE TEST_SPLITTING (!POSITIONAL !enclose( '(' , ')' )).
INPUT PROGRAM.
LOOP iD=1 TO 5.
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
FORMAT iD (F3.0).
LIST.
!DO !VARL !IN (!1).
!LET !V_Var1 = !UNQUOTE(!CONCAT(!SUBSTRING(!VARL,1,!INDEX(!VARL,'.')), !
SUBSTRING(!VARL, !INDEX(!VARL, '.')))).
COMPUTE !V_Var1 = 1.
!LET !V_Var2 = !UNQUOTE(!CONCAT(!SUBSTRING(!VARL,1,!INDEX(!VARL,'.')), !
SUBSTRING(!SUBSTRING(!VARL, !INDEX(!VARL, '.')),2))).
COMPUTE !V_Var2 = 2.
!LET !REVERSE_Var3 = !UNQUOTE(!CONCAT(!SUBSTRING(!SUBSTRING(!VARL, !INDEX(!
VARL, '.')),2), '.', !SUBSTRING(!VARL,1,!INDEX(!VARL,'.')))).
COMPUTE !REVERSE_Var3 = 3.
EXECUTE.
!DOEND.
!ENDDEFINE.

TEST_SPLITTING(a1.b2 c1.d2).

Parameters a1.b2 c1.d2 etc. are sources for the names of the new
variables.

1st Question:

!LET !REVERSE_Var3 = !UNQUOTE(!CONCAT(!SUBSTRING(!SUBSTRING(!VARL, !INDEX(!
VARL, '.')),2), '.', !SUBSTRING(!VARL,1,!INDEX(!VARL,'.')))).
This construction puts a period at the end of the variable name. Is it
possible to do it without the period?

This way it doesn't work:
COMPUTE REVERSE_Var4 = !UNQUOTE(!CONCAT(!SUBSTRING(!VARL, !INDEX(!
VARL, '.') + 1), '.', !SUBSTRING(!VARL,1,!INDEX(!VARL,'.') - 1))).


2nd Question:
I would like to create something along the lines of the following:
...
!LET !HEAD_I = !SUBSTRING(!VARL, 1, !INDEX(!VARL, '.') - 1).
!LET !TAIL_I = !SUBSTRING(!VARL, !INDEX(!VARL, '.') + 1).
!LET !REVERSE_V = !UNQUOTE(!CONCAT(!TAIL_I, !HEAD_I)).
!LET !THT_V = !UNQUOTE(!CONCAT(!TAIL_I, !HEAD_I, !TAIL_I)).
...

where:

HEAD_I, TAIL_I   - names of intermediary variables;
REVERSE_V, THT_V  - names of variables that the program will read or
create in the .sav file. There could be any other variables of the ‘_V’
type.

I hope I made myself more clear this time. Thank you very much for your
help, you have been very helpful in my SPSS endeavors!
Simon

=====================
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