select if using string wildcards

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

select if using string wildcards

wsu_wright
I'm trying to select a substring that has variable string values.  Let's
say I have a string that contains multiple major codes as in

id(1) majors(3-16)
1 A25Q G20F A43D
2 B12G C34D
3 H12D A23K G25D
4 G13E
5 D34S

And let's say I want to select only records that have a major starting
with 'G' so that I would have only:
1 A25Q G20F A43D
3 H12D A23K G25D
4 G13E

I was thinking if:

Select if (INDEX(majors),'G'>0).

But the above would also select record 2 which contains B12G.

Is it possible to use a wildcard to select only those with a G# ?



David

=====================
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: select if using string wildcards

Art Kendall
If your raw data is in a fixed format you could read it into 4 variables.

One approach would be to write the variable majors out into a text file and read it back in.

another approach would be something like
select if substr(majors,1,1) eq 'G' or index(majors, ' G' gt 0).

Art Kendall
Social Research Consultants

On 4/19/2011 4:18 PM, David Wright wrote:
I'm trying to select a substring that has variable string values.  Let's
say I have a string that contains multiple major codes as in

id(1) majors(3-16)
1 A25Q G20F A43D
2 B12G C34D
3 H12D A23K G25D
4 G13E
5 D34S

And let's say I want to select only records that have a major starting
with 'G' so that I would have only:
1 A25Q G20F A43D
3 H12D A23K G25D
4 G13E

I was thinking if:

Select if (INDEX(majors),'G'>0).

But the above would also select record 2 which contains B12G.

Is it possible to use a wildcard to select only those with a G# ?



David

=====================
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: select if using string wildcards

Rich Ulrich
In reply to this post by wsu_wright
You have mis-written your use of INDEX( ); check the HELP.  Also,
I think I remember that there is a version of INDEX( )  which
includes a spacing-parameter.  So you can ask for a match in
column 1, spacing 5, which is exactly what you want.

If there is no "spacing", then you can resort to creating
a new string LMAJ  which concatenates a blank + the original
string.  Then you would search for " G" -- blank-G.

--
Rich Ulrich




=====================
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: select if using string wildcards

wsu_wright
In reply to this post by wsu_wright
Thanks Art.

After reading your suggestion & looking at the data again, you made me see that the we do in fact have 2 conditions in which G is either in byte 1 or has a space in front of it, so (untested) this should work:

Select if (INDEX(majors),'G'=1) or  (INDEX(majors),' G'>0).


David


On Tue, Apr 19, 2011 at 3:34 PM, Art Kendall wrote:

 If your raw data is in a fixed format you could read       it into 4 variables.

One approach would be to write the variable majors out into a text       file and read it back in.

another approach would be something like
select if substr(majors,1,1) eq 'G' or         index(majors, ' G' gt 0).

Art Kendall
Social Research Consultants

On 4/19/2011 4:18 PM, David Wright wrote: I'm trying to select a substring that has variable       string values.  Let's
say I have a string that contains multiple major codes as in

id(1) majors(3-16)
1 A25Q G20F A43D
2 B12G C34D
3 H12D A23K G25D
4 G13E
5 D34S

And let's say I want to select only records that have a major       starting
with 'G' so that I would have only:
1 A25Q G20F A43D
3 H12D A23K G25D
4 G13E

I was thinking if:

Select if (INDEX(majors),'G'>0).

But the above would also select record 2 which contains B12G.

Is it possible to use a wildcard to select only those with a G# ?



David

=====================
To manage your subscription to SPSSX-L, send a message to
<A HREF="javascript:parent.wgMail.openComposeWindow('LISTSERV@LISTSERV.UGA.EDU')" TARGET="">LISTSERV@...(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: select if using string wildcards

wsu_wright
In reply to this post by wsu_wright
Good catch Rich, the corrected syntax below now works:
select if INDEX(majors,'G')=1 or INDEX(majors,' G')>0.

On Tue, Apr 19, 2011 at 3:41 PM, Rich Ulrich wrote:

> You have mis-written your use of INDEX( ); check the HELP.  Also,
> I think I remember that there is a version of INDEX( )  which
> includes a spacing-parameter.  So you can ask for a match in
> column 1, spacing 5, which is exactly what you want.
>
> If there is no "spacing", then you can resort to creating
> a new string LMAJ  which concatenates a blank + the original
> string.  Then you would search for " G" -- blank-G.
>
> --
> Rich Ulrich
>
>
>
>
> =====================
> 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