Date: Thu, 29 Sep 2005 17:28:34 -0400
Reply-To: Richard Ristow <wrristow@mindspring.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Richard Ristow <wrristow@mindspring.com>
Subject: Re: String Transformation
In-Reply-To: <3B31B3436E1BF040B1DB268B0A6D01B154F643@amer-mail-05.amer.i
ncepta.net>
Content-Type: text/plain; charset="us-ascii"; format=flowed
At 12:39 PM 9/29/2005, Arthur Aguirre wrote:
>I have the following compute function:
>
>comp x=concat("if"," ","y=","""",ltrim(rtrim(y)),"""","","code=","
>",".").
>
>It would be useful to insert tab spaces verses singles spaces (" ").
>Anyone know if this is possible?
Do you mean, having the components, like "y=", starting at fixed
positions in the string? If so, it can be done, but the neck is what
it's a pain in. I've done it this way, though this particular code is
untested.
Suppose you want 'y=' to start in position 8;
the literal """",ltrim(rtrim(y)),"""","" to start in position 14;
the assignment and command terminator "code=","","." to start in
position 26;
First, I'm going to recast your expressions so literals in YOUR code
are delimited by single quote, and literals in the OUTPUT code
delimited by double quotes. Sorry: code that writes code is very hard
to read at the best of times. Very much including my own, for that
purpose. If I get this right, it may be a little easier to read. (But I
don't think it is wholly right.)
Position 01: 'if'
Position 08: 'y='
Position 14: CONCAT('"', ltrim(rtrim(y)), '"', '')
Position 26: CONCAT('code=', '', '.').
The pain in the neck
COMPUTE x = 'if'.
COMPUTE SUBSTR(x,08) = 'y='.
COMPUTE SUBSTR(x,14) = CONCAT('"',
ltrim(rtrim(y)),
'"', '').
COMPUTE SUBSTR(x,26) = CONCAT('code=', '', '.').
I'm sure I've got syntax errors in there. Maybe, at least that's a
usable idea.
|