Split parameter, PLEASE HELP

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Split parameter, PLEASE HELP

Simon Levin
Hi all, great website!

I am using SPSS 16.0 and have the following question, I am trying to split
each parameter (aa.bb cc.dd) into 2 parts, so that they can be used as
intermediary names (head, tail). Below is a fragment of my macro that does
not work. Is there a way of doing that?

DEFINE TEST_SPLITTING (!POSITIONAL !ENCLOSE( '(' , ')' )).
...
!LET !HEAD = !SUBSTRING(!QUOTE(!1), 1, !INDEX(!QUOTE(!1), '.') - 1).
!LET !TAIL = !SUBSTRING(!QUOTE(!1), !INDEX(!QUOTE(!1), '.') + 1).
!LET !REVERSE = !CONCAT(!TAIL, !HEAD).
!LET !TRT = !CONCAT(!TAIL, !HEAD, !TAIL).
...
!ENDDEFINE.

TEST_SPLITTING(aa.bb cc.dd).

Thank you very much for your help!
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
Reply | Threaded
Open this post in threaded view
|

Re: Split parameter, PLEASE HELP

Albert-Jan Roskam
Hi,

This is so much easier to do in Python:

line = "aa.bb"
head, tail = line.split(".")[0], line.split(".")[1]
reverse = tail + head
trt = tail + head + tail

You could easily transform this into a function.

Cheers!!
Albert-Jan



--- On Tue, 10/28/08, Simon Levin <[hidden email]> wrote:

> From: Simon Levin <[hidden email]>
> Subject: Split parameter, PLEASE HELP
> To: [hidden email]
> Date: Tuesday, October 28, 2008, 7:04 PM
> Hi all, great website!
>
> I am using SPSS 16.0 and have the following question, I am
> trying to split
> each parameter (aa.bb cc.dd) into 2 parts, so that they can
> be used as
> intermediary names (head, tail). Below is a fragment of my
> macro that does
> not work. Is there a way of doing that?
>
> DEFINE TEST_SPLITTING (!POSITIONAL !ENCLOSE( '(' ,
> ')' )).
> ...
> !LET !HEAD = !SUBSTRING(!QUOTE(!1), 1, !INDEX(!QUOTE(!1),
> '.') - 1).
> !LET !TAIL = !SUBSTRING(!QUOTE(!1), !INDEX(!QUOTE(!1),
> '.') + 1).
> !LET !REVERSE = !CONCAT(!TAIL, !HEAD).
> !LET !TRT = !CONCAT(!TAIL, !HEAD, !TAIL).
> ...
> !ENDDEFINE.
>
> TEST_SPLITTING(aa.bb cc.dd).
>
> Thank you very much for your help!
> 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

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Split parameter, PLEASE HELP

Richard Ristow
In reply to this post by Simon Levin
At 02:04 PM 10/28/2008, Simon Levin wrote:

>I am using SPSS 16.0. I am trying to split each parameter (aa.bb
>cc.dd) into 2 parts, so that they can be used as intermediary names
>(head, tail).

Albert-Jan may well be right, that Python is the way to go, though
the string processing can certainly be done in DEFINE language as well.

But, can you tell us how you'll be using this? That is, what are your
parameters and where do they come from - production-mode macro
symbols, maybe? And, what will you do with the results?

Can you give an example of how you'd use your macro TEST_SPLITTING,
or the production macro you'd eventually like to have? It'll help a
lot in our deciding what solution to advise.

-Best of luck,
  Richard Ristow

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Split parameter, PLEASE HELP

Simon Levin
In reply to this post by Simon Levin
Hi Richard,

Thanks for your response. I fixed my example a little:

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.

Parameters aa.bb cc.dd etc. are sources for the names of the ‘_V’ type
variables.

DEFINE TEST_SPLITTING (!POSITIONAL !ENCLOSE( '(' , ')' )).
...
!LET !HEAD_I = !SUBSTRING(!QUOTE(!1), 1, !INDEX(!QUOTE(!1), '.') - 1).
!LET !TAIL_I = !SUBSTRING(!QUOTE(!1), !INDEX(!QUOTE(!1), '.') + 1).
!LET !REVERSE_V = !CONCAT(!TAIL_I, !HEAD_I).
!LET !THT_V = !CONCAT(!TAIL_I, !HEAD_I, !TAIL_I).
...
!ENDDEFINE.

TEST_SPLITTING(aa.bb cc.dd).

I hope this explains better. Thank you very much for your help!
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