ANY function

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

ANY function

Maguin, Eugene
All,

I'd like to test whether a A1 string var matches any of a set of punctuation
characters. I'd swear that I have seen something like this used

IF (ANY(CHAR,'!,.?";:')).

Am I imagining this sort of structure or is there really a way to do this?

Let me add that I've reviewed the syntax ref and have seen an example such
as

ANY(X,2,3,4,5,6,7,8)

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

Re: ANY function

ViAnn Beadle
Every string must be individually quoted.
You might also consider a python solution which has better pattern matching.
-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Gene Maguin
Sent: Friday, March 27, 2009 2:52 PM
To: [hidden email]
Subject: ANY function

All,

I'd like to test whether a A1 string var matches any of a set of punctuation
characters. I'd swear that I have seen something like this used

IF (ANY(CHAR,'!,.?";:')).

Am I imagining this sort of structure or is there really a way to do this?

Let me add that I've reviewed the syntax ref and have seen an example such
as

ANY(X,2,3,4,5,6,7,8)

Thanks, 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

=====================
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: ANY function

David Marso
Administrator
In reply to this post by Maguin, Eugene
Hi Gene,
See INDEX function.
IF INDEX(CHAR,'!,.?";:',1).  Be careful of single and double quotes. 
May need IF INDEX(CHAR,'!,.?";:',1)> 0 OR CHAR="'"....
HTH, David
-----------
                                                                   
                                                                    
                                            
>All,

>I'd like to test whether a A1 string var matches any >of a set of punctuation
>characters. I'd swear that I have seen something like >this used

>IF (ANY(CHAR,'!,.?";:')).
>Am I imagining this sort of structure or is there really a >way to do this?

>Let me add that I've reviewed the syntax ref and >have seen an example such
>as
>ANY(X,2,3,4,5,6,7,8)
>Thanks, Gene Maguin

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

Re: ANY function

Hal 9000
compute flag=index(char, '!' , '?' , ';' , ',' , '1')>0.
select if ~flag /*ostensibly*/.
freq char.

*?*.

On Sat, Mar 28, 2009 at 12:21 AM, David Marso <[hidden email]> wrote:

> Hi Gene,
> See INDEX function.
> IF INDEX(CHAR,'!,.?";:',1).  Be careful of single and double quotes.
> May need IF INDEX(CHAR,'!,.?";:',1)> 0 OR CHAR="'"....
> HTH, David
> -----------
>
>
>
>>All,
>
>>I'd like to test whether a A1 string var matches any >of a set of
>> punctuation
>>characters. I'd swear that I have seen something like >this used
>
>>IF (ANY(CHAR,'!,.?";:')).
>>Am I imagining this sort of structure or is there really a >way to do this?
>
>>Let me add that I've reviewed the syntax ref and >have seen an example such
>>as
>>ANY(X,2,3,4,5,6,7,8)
>>Thanks, 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
Reply | Threaded
Open this post in threaded view
|

Re: ANY function

Albert-Jan Roskam
In reply to this post by Maguin, Eugene
Hi Gene,

Untested (don't have spss on this computer):
compute punctuated = (index(any(sourcevar, ":", ";", ",")) > 0).

In Python you use a regular expression
regex = re.search("\W", s)
where s is the string to be searched.

Cheers!!
Albert-Jan



--- On Fri, 3/27/09, ViAnn Beadle <[hidden email]> wrote:

> From: ViAnn Beadle <[hidden email]>
> Subject: Re: ANY function
> To: [hidden email]
> Date: Friday, March 27, 2009, 11:04 PM
> Every string must be individually
> quoted.
> You might also consider a python solution which has better
> pattern matching.
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]]
> On Behalf Of
> Gene Maguin
> Sent: Friday, March 27, 2009 2:52 PM
> To: [hidden email]
> Subject: ANY function
>
> All,
>
> I'd like to test whether a A1 string var matches any of a
> set of punctuation
> characters. I'd swear that I have seen something like this
> used
>
> IF (ANY(CHAR,'!,.?";:')).
>
> Am I imagining this sort of structure or is there really a
> way to do this?
>
> Let me add that I've reviewed the syntax ref and have seen
> an example such
> as
>
> ANY(X,2,3,4,5,6,7,8)
>
> Thanks, 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
>
> =====================
> 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: ANY function

Ruben Geert van den Berg
Dear all,
 
The syntax below should create a string (BLA) and 'TEST' should indicate whether any character within BLA contains any 3 or any r. Could anyone please point out what's going wrong here?
 
Best regards,
 
Ruben v.d. Berg
 
DATA LIST FREE/BLA (A4).
BEGIN DATA
"j3" "R" "r" "Bla2" "" "12"
END DATA.
 
STRING test (A3).
EXE.
 
compute TEST = (index(any(BLA, '3', 'r')) > 0).
EXE.




 

> Date: Sat, 28 Mar 2009 02:05:01 -0700
> From: [hidden email]
> Subject: Re: ANY function
> To: [hidden email]
>
> Hi Gene,
>
> Untested (don't have spss on this computer):
> compute punctuated = (index(any(sourcevar, ":", ";", ",")) > 0).
>
> In Python you use a regular expression
> regex = re.search("\W", s)
> where s is the string to be searched.
>
> Cheers!!
> Albert-Jan
>
>
>
> --- On Fri, 3/27/09, ViAnn Beadle <[hidden email]> wrote:
>
> > From: ViAnn Beadle <[hidden email]>
> > Subject: Re: ANY function
> > To: [hidden email]
> > Date: Friday, March 27, 2009, 11:04 PM
> > Every string must be individually
> > quoted.
> > You might also consider a python solution which has better
> > pattern matching.
> > -----Original Message-----
> > From: SPSSX(r) Discussion [mailto:[hidden email]]
> > On Behalf Of
> > Gene Maguin
> > Sent: Friday, March 27, 2009 2:52 PM
> > To: [hidden email]
> > Subject: ANY function
> >
> > All,
> >
> > I'd like to test whether a A1 string var matches any of a
> > set of punctuation
> > characters. I'd swear that I have seen something like this
> > used
> >
> > IF (ANY(CHAR,'!,.?";:')).
> >
> > Am I imagining this sort of structure or is there really a
> > way to do this?
> >
> > Let me add that I've reviewed the syntax ref and have seen
> > an example such
> > as
> >
> > ANY(X,2,3,4,5,6,7,8)
> >
> > Thanks, 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
> >
> > =====================
> > 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


Express yourself instantly with MSN Messenger! MSN Messenger
Reply | Threaded
Open this post in threaded view
|

Re: ANY function

Richard Ristow
At 04:22 AM 3/29/2009, Ruben van den Berg wrote:

The syntax below should create a string (BLA) and 'TEST' should indicate whether any character within BLA contains any 3 or any r. Could anyone please point out what's going wrong here?

First, to get this off my chest: You don't need the EXECUTE statements. All they do is slow your processing.

 
DATA LIST FREE/BLA (A4).
BEGIN DATA
"j3" "R" "r" "Bla2" "" "12"
END DATA.
 
STRING test (A3).
*xxxxx   EXE   xxxxx.
 
compute TEST = (index(any(BLA, '3', 'r')) > 0).
*xxxxx   EXE   xxxxx.

It's probably blowing up on you, with an error message. The expression

any(BLA, '3', 'r')

has a numeric result (1 for 'yes,' 0 for 'no'), so it's not acceptable as an argument to INDEX. And anyway, it tests whether "BLA" is '3' or 'r', not whether it contains them.

David Marso had it right: this is where you use the third argument to INDEX. From the Command Syntax Reference:

INDEX(a1, a2, a3)

Return a number that indicates the position of the first occurrence of a2 in a1.( a1 is the string that is searched. a2 is the string variable or string that is [searched for].)  The optional a3 is the number of characters used to divide a2 into separate strings. For example, INDEX(var1, 'abcd', 1) will return the value of the position of the first occurrence of any of 'a', 'b', 'c', or 'd']. If a2 is not found within a1 , the value 0 is returned.

So, try

.  compute TEST = (index(BLA,'3r',1) > 0).

Notice that '3' and 'r' are characters in a single string, not separate string arguments.
====================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
|

date function

Lombardo, Barbara
In reply to this post by Hal 9000
Hello all,

When I pass a week number to this function DATE.WKYR(WK,2010) and this
function DATE.WKYR(WK,2009), they come back with the exact month and
day.  I am assuming this function is supposed to give me the first day
date of the week that I pass it in the corresponding year.  This is not
the case.  Does anyone know how to get what I am looking for?

Thank you


Barbara Lombardo

=====================
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: date function

Maguin, Eugene
Barbara,

So, if you go
Compute date1-date.wkyr(10,2009).
Compute date2-date.wkyr(10,2010).

What is the exact value of date1 and date2, as in Monday, Jan 13, 2009?

Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Lombardo, Barbara
Sent: Tuesday, June 22, 2010 11:25 AM
To: [hidden email]
Subject: date function

Hello all,

When I pass a week number to this function DATE.WKYR(WK,2010) and this
function DATE.WKYR(WK,2009), they come back with the exact month and
day.  I am assuming this function is supposed to give me the first day
date of the week that I pass it in the corresponding year.  This is not
the case.  Does anyone know how to get what I am looking for?

Thank you


Barbara Lombardo

=====================
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: date function

Rick Oliver-3
In reply to this post by Lombardo, Barbara

Why do you think it is not returning the first day of the week?

A very cursory test indicates that it does return the first day of the week:

data list free /week year.
begin data
1 2009
3 2009
end data.
compute weekstart=date.wkyr(week,year).
formats weekstart(adate10).
list.

Note that the start of each week is different for each year, since week one is always starts on January 1, and January 1 is a different day of the week each year.


From: "Lombardo, Barbara" <[hidden email]>
To: [hidden email]
Date: 06/22/2010 10:23 AM
Subject: date function
Sent by: "SPSSX(r) Discussion" <[hidden email]>





Hello all,

When I pass a week number to this function DATE.WKYR(WK,2010) and this
function DATE.WKYR(WK,2009), they come back with the exact month and
day.  I am assuming this function is supposed to give me the first day
date of the week that I pass it in the corresponding year.  This is not
the case.  Does anyone know how to get what I am looking for?

Thank you


Barbara Lombardo

=====================
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: date function

Maguin, Eugene
In reply to this post by Lombardo, Barbara
Barbara,

The key point is that spss computes week number by counting Jan 1 as day 1
of week 1. Doing what you want to do is not too hard to do. Three questions
for you are 1) what day of the week is day 1? Sunday or Monday? 2) Is your
definition of week 1 of a year that week that included Jan 1? So that for
2010, week 1 includes Jan 1 and Jan 2 (treating Sunday as day 1 of the
week)? Or, is it something different? If so, please define. And 3) do you
want this to work for any year or for a specific year. What I mean by this
is that 1+trunc(Julian day/7) is the spss defined week count.

Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Lombardo, Barbara
Sent: Tuesday, June 22, 2010 11:25 AM
To: [hidden email]
Subject: date function

Hello all,

When I pass a week number to this function DATE.WKYR(WK,2010) and this
function DATE.WKYR(WK,2009), they come back with the exact month and
day.  I am assuming this function is supposed to give me the first day
date of the week that I pass it in the corresponding year.  This is not
the case.  Does anyone know how to get what I am looking for?

Thank you


Barbara Lombardo

=====================
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: date function

Maguin, Eugene
Jon,

I may have misunderstood your posting and be hearing something that is not
there but I wasn't intending a criticism of spss' method of computing week
number. If my posting conveyed that, I apologize. I've been rantingly
critical in the past but I'm not trying to set that up here.

Gene Maguin

>>>There are several different week numbering systems in use around the
world.  Week 1 could start on Jan 1, on the date that first includes the day
defined as start of week, or on the first interval that at least four days
long and includes the start-of-week day.  On top of this, the week might
start on Sunday or Monday.  And there are probably other numbering systems
to be found out in the wild.  So SPSS doesn't try to reproduce all these
variations.  And I'm not going near numbering the weeks in a month :-)

=====================
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: date function

Maguin, Eugene
In reply to this post by Maguin, Eugene
Barbara,

Sorry, for getting back to you so slowly.

Here's what I'm proposing to do. 1) Define 'week' as being Monday thru
Sunday, which differs from spss' definition of Sunday through Saturday. 2)
Define week 1 as the week that contains Jan 1

There's two cases to consider.
1) Jan 1 falls on a Monday.
2) Jan 1 falls on any other day.

I'm not sure how you will use this. I'll assume that you want to input a
week number and a year and return  the date that corrresponds to the Monday
of that week. Therefore,
WeekNum = input week number,
Year = input year,
MondayWeekYear = the date of the Monday given week and year.

Compute WkDay=xdate.wkday(date.mdy(1,1,year)).
if (WkDay eq 1) WkDay=8. /* Jan 1 is a Sunday.
Do if (WkDay eq 2).  /* case 1: Jan 1 is a Monday.
+  compute MondayWeekYear=date.wkyr(weeknum,year).
Else. /* case 2: Jan 1 is not a Monday.
+  compute MondayWeekYear=date.wkyr(weeknum,year)-(WkDay-2)*24*3600.
End if.
format MondayWeekYear(adate10).
execute.

I did a little testing with this and it seems to work ok. The one place I'm
not sure about is what happens at the end of the year. You may have noticed
that the date.wknum function takes values between 1 and 52. As previously
noted, date.wknum(1,year) returns Jan 1, year. I figure that
date.wknum(52,year) returns Dec 24 in a non leap-year and Dec 23 in a leap
year. Because there are 52 full weeks in a year and always one partial week
that always contains Jan 1. Actually, then, I think there is an spss
question here.

Someone from spss: Are my calculations corrrect? If so, shouldn't the
allowable range for date.wknum be 1-53 instead of 1-52?


Gene Maguin





-----Original Message-----
From: Lombardo, Barbara [mailto:[hidden email]]
Sent: Wednesday, June 23, 2010 10:09 AM
To: Gene Maguin
Subject: RE: Re: date function

Hi Gene,

Yes, I want this to work for any year and our week starts on Monday.
I am trying to compare enrollments numbers by past and present year.  As
long as the weeks are consistent is should not matter if Jan 1 is included
in week one or not.

Thank you

Barbara Lombardo


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Gene Maguin
Sent: Tuesday, June 22, 2010 3:30 PM
To: [hidden email]
Subject: Re: date function

Barbara,

The key point is that spss computes week number by counting Jan 1 as day 1
of week 1. Doing what you want to do is not too hard to do. Three questions
for you are 1) what day of the week is day 1? Sunday or Monday? 2) Is your
definition of week 1 of a year that week that included Jan 1? So that for
2010, week 1 includes Jan 1 and Jan 2 (treating Sunday as day 1 of the
week)? Or, is it something different? If so, please define. And 3) do you
want this to work for any year or for a specific year. What I mean by this
is that 1+trunc(Julian day/7) is the spss defined week count.

Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Lombardo, Barbara
Sent: Tuesday, June 22, 2010 11:25 AM
To: [hidden email]
Subject: date function

Hello all,

When I pass a week number to this function DATE.WKYR(WK,2010) and this
function DATE.WKYR(WK,2009), they come back with the exact month and
day.  I am assuming this function is supposed to give me the first day
date of the week that I pass it in the corresponding year.  This is not
the case.  Does anyone know how to get what I am looking for?

Thank you


Barbara Lombardo

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