Operators in macro

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

Operators in macro

Jignesh Sutar
 Hi there,
 
I've simplified the macro to demonstrate the problem. I'm looping over a list of vars and concatenating blanks to keep a track of the loop number however it interprets 10 to be less than 3 (using the example below)?
 
If I however change "<" to "=" in the line "!if (!len(!counter) < !number) !then" then it always interprets it correctly. Please can someone shed some light to this!
 
input program.
vector v(20,f1).
loop id = 1 to 10.
loop #v = 1 to 20.
compute v(#v)=rnd(rv.uniform(1,5)).
end loop.
end case.
end loop.
end file.
end input program.
exe.
 
define !demo (vars=!charend('/')
                    /number =!charend('/'))
!let !counter=!blanks(0)
!do !i !in (!vars)
    !let !counter=!concat(!counter,!blanks(1))
    title counter lengeth equals !len(!counter).
    !if (!len(!counter) < !number) !then
        freq !i.
    !ifend
!doend
!enddefine.
set printback on mprint on.
!demo vars=V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
                 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 /number=3.
set mprint off.
Reply | Threaded
Open this post in threaded view
|

Re: Operators in macro

Bruce Weaver
Administrator
J Sutar wrote
 Hi there,

I've simplified the macro to demonstrate the problem. I'm looping over a
list of vars and concatenating blanks to keep a track of the loop number
however it interprets 10 to be less than 3 (using the example below)?

If I however change "*<*" to "*=*" in the line "*!if (!len(!counter) <
!number) !then*" then it always interprets it correctly. Please can someone
shed some light to this!

input program.
vector v(20,f1).
loop id = 1 to 10.
loop #v = 1 to 20.
compute v(#v)=rnd(rv.uniform(1,5)).
end loop.
end case.
end loop.
end file.
end input program.
exe.

define !demo (vars=!charend('/')
                    /number =!charend('/'))
!let !counter=!blanks(0)
!do !i !in (!vars)
    !let !counter=!concat(!counter,!blanks(1))
    title counter lengeth equals !len(!counter).
    !if (!len(!counter) < !number) !then
        freq !i.
    !ifend
!doend
!enddefine.
set printback on mprint on.
!demo vars=V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
                 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 /number=3.
set mprint off.
No idea why that's misbehaving.  But how about this as an alternative way of getting it done?  Notice that I changed your second !charend('/') to !cmdend.  I also assume that you want to loop from 1 to !number, not to !number-1.


define !demo (vars=!charend('/') /
              number =!cmdend)
!let !vcopy = !vars
!do !i = 1 !to !number
!let !v = !head(!vcopy)
!let !vcopy = !tail(!vcopy)
freq !v.
!doend
!enddefine.

set printback on mprint on.
!demo vars=V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
                 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 /number=3.
set mprint off.

HTH.

--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Operators in macro

David Marso
Administrator
In reply to this post by Jignesh Sutar
"Please can someone shed some light to this!"
What is being compared are strings, not 'numbers'.
ie 1 < 10 < 11 < 2
Here is a workaround (!BREAK).
HTH, David

define !demo (vars=!charend('/')
                    /number =!charend('/'))
!let !counter=!blanks(0)
!let !test=!blanks(0)
!do !t=1 !to !number !let !test=!concat(!test,!blanks(1)) !doend
!do !i !in (!vars)
    !let !counter=!concat(!counter,!blanks(1))
    title counter lengeth equals !len(!counter).
    !if (!len(!counter) !LE !len(!test)  ) !then
        freq !i.
    !ifend
    !if  (!len(!counter) !EQ !len(!test)) !then !break  !ifend
!doend
!enddefine.
set printback on mprint on.
!demo vars=V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
                 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 /number=9.
set mprint off.
J Sutar wrote
 Hi there,

I've simplified the macro to demonstrate the problem. I'm looping over a
list of vars and concatenating blanks to keep a track of the loop number
however it interprets 10 to be less than 3 (using the example below)?

If I however change "*<*" to "*=*" in the line "*!if (!len(!counter) <
!number) !then*" then it always interprets it correctly. Please can someone
shed some light to this!

input program.
vector v(20,f1).
loop id = 1 to 10.
loop #v = 1 to 20.
compute v(#v)=rnd(rv.uniform(1,5)).
end loop.
end case.
end loop.
end file.
end input program.
exe.

define !demo (vars=!charend('/')
                    /number =!charend('/'))
!let !counter=!blanks(0)
!do !i !in (!vars)
    !let !counter=!concat(!counter,!blanks(1))
    title counter lengeth equals !len(!counter).
    !if (!len(!counter) < !number) !then
        freq !i.
    !ifend
!doend
!enddefine.
set printback on mprint on.
!demo vars=V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
                 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 /number=3.
set mprint off.
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: Operators in macro

Jon K Peck
In reply to this post by Bruce Weaver
As I told the user offline, the comparison is being made lexicographically as strings, where "1" is less than "3".

Jon Peck
Senior Software Engineer, IBM
[hidden email]
312-651-3435




From:        Bruce Weaver <[hidden email]>
To:        [hidden email]
Date:        12/22/2010 10:49 AM
Subject:        Re: [SPSSX-L] Operators in macro
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




J Sutar wrote:
>
>  Hi there,
>
> I've simplified the macro to demonstrate the problem. I'm looping over a
> list of vars and concatenating blanks to keep a track of the loop number
> however it interprets 10 to be less than 3 (using the example below)?
>
> If I however change "*<*" to "*=*" in the line "*!if (!len(!counter) <
> !number) !then*" then it always interprets it correctly. Please can
> someone
> shed some light to this!
>
> input program.
> vector v(20,f1).
> loop id = 1 to 10.
> loop #v = 1 to 20.
> compute v(#v)=rnd(rv.uniform(1,5)).
> end loop.
> end case.
> end loop.
> end file.
> end input program.
> exe.
>
> define !demo (vars=!charend('/')
>                     /number =!charend('/'))
> !let !counter=!blanks(0)
> !do !i !in (!vars)
>     !let !counter=!concat(!counter,!blanks(1))
>     title counter lengeth equals !len(!counter).
>     !if (!len(!counter) < !number) !then
>         freq !i.
>     !ifend
> !doend
> !enddefine.
> set printback on mprint on.
> !demo vars=V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
>                  V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 /number=3.
> set mprint off.
>
>

No idea why that's misbehaving.  But how about this as an alternative way of
getting it done?  Notice that I changed your second !charend('/') to
!cmdend.  I also assume that you want to loop from 1 to !number, not to
!number-1.


define !demo (vars=!charend('/') /
             number =!cmdend)
!let !vcopy = !vars
!do !i = 1 !to !number
!let !v = !head(!vcopy)
!let !vcopy = !tail(!vcopy)
freq !v.
!doend
!enddefine.

set printback on mprint on.
!demo vars=V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
                V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 /number=3.
set mprint off.

HTH.



-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Operators-in-macro-tp3315178p3315424.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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: Operators in macro

Bruce Weaver
Administrator
Hi Jon.  That occurred to me, so I tried this variation on the original macro:

define !demo (vars=!charend('/') /
              number =!cmdend)
!let !counter=!blanks(0)
!let !max = !blanks(!number)
!do !i !in (!vars)
    !let !counter=!concat(!counter,!blanks(1))
    title counter length equals !len(!counter).
    !if (!len(!counter) !LE !len(!max)) !then       <-- notice the change here
        freq !i.
    !ifend
!doend
!enddefine.


But it still did not work, and I'm not sure why.  Any thoughts?

bw


Jon K Peck wrote
As I told the user offline, the comparison is being made lexicographically
as strings, where "1" is less than "3".

Jon Peck
Senior Software Engineer, IBM
peck@us.ibm.com
312-651-3435



From:   Bruce Weaver <bruce.weaver@hotmail.com>
To:     SPSSX-L@LISTSERV.UGA.EDU
Date:   12/22/2010 10:49 AM
Subject:        Re: [SPSSX-L] Operators in macro
Sent by:        "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>



J Sutar wrote:
>
>  Hi there,
>
> I've simplified the macro to demonstrate the problem. I'm looping over a
> list of vars and concatenating blanks to keep a track of the loop number
> however it interprets 10 to be less than 3 (using the example below)?
>
> If I however change "*<*" to "*=*" in the line "*!if (!len(!counter) <
> !number) !then*" then it always interprets it correctly. Please can
> someone
> shed some light to this!
>
> input program.
> vector v(20,f1).
> loop id = 1 to 10.
> loop #v = 1 to 20.
> compute v(#v)=rnd(rv.uniform(1,5)).
> end loop.
> end case.
> end loop.
> end file.
> end input program.
> exe.
>
> define !demo (vars=!charend('/')
>                     /number =!charend('/'))
> !let !counter=!blanks(0)
> !do !i !in (!vars)
>     !let !counter=!concat(!counter,!blanks(1))
>     title counter lengeth equals !len(!counter).
>     !if (!len(!counter) < !number) !then
>         freq !i.
>     !ifend
> !doend
> !enddefine.
> set printback on mprint on.
> !demo vars=V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
>                  V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 /number=3.
> set mprint off.
>
>

No idea why that's misbehaving.  But how about this as an alternative way
of
getting it done?  Notice that I changed your second !charend('/') to
!cmdend.  I also assume that you want to loop from 1 to !number, not to
!number-1.


define !demo (vars=!charend('/') /
              number =!cmdend)
!let !vcopy = !vars
!do !i = 1 !to !number
!let !v = !head(!vcopy)
!let !vcopy = !tail(!vcopy)
freq !v.
!doend
!enddefine.

set printback on mprint on.
!demo vars=V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
                 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 /number=3.
set mprint off.

HTH.



-----
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Operators-in-macro-tp3315178p3315424.html

Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Operators in macro

David Marso
Administrator
Hi Bruce,
I'll bet that the !Len comparisons are also string compares.
"  !if (!len(!counter) !LE !len(!max)) !then    "
Hence my !BREAK 'hack'
I believe the !HEAD/!TAIL method you posted is far better than the original or my !BREAK 'hack'.
David

Bruce Weaver wrote
Hi Jon.  That occurred to me, so I tried this variation on the original macro:

define !demo (vars=!charend('/') /
              number =!cmdend)
!let !counter=!blanks(0)
!let !max = !blanks(!number)
!do !i !in (!vars)
    !let !counter=!concat(!counter,!blanks(1))
    title counter length equals !len(!counter).
    !if (!len(!counter) !LE !len(!max)) !then       <-- notice the change here
        freq !i.
    !ifend
!doend
!enddefine.


But it still did not work, and I'm not sure why.  Any thoughts?

bw


Jon K Peck wrote
As I told the user offline, the comparison is being made lexicographically
as strings, where "1" is less than "3".

Jon Peck
Senior Software Engineer, IBM
peck@us.ibm.com
312-651-3435



From:   Bruce Weaver <bruce.weaver@hotmail.com>
To:     SPSSX-L@LISTSERV.UGA.EDU
Date:   12/22/2010 10:49 AM
Subject:        Re: [SPSSX-L] Operators in macro
Sent by:        "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>



J Sutar wrote:
>
>  Hi there,
>
> I've simplified the macro to demonstrate the problem. I'm looping over a
> list of vars and concatenating blanks to keep a track of the loop number
> however it interprets 10 to be less than 3 (using the example below)?
>
> If I however change "*<*" to "*=*" in the line "*!if (!len(!counter) <
> !number) !then*" then it always interprets it correctly. Please can
> someone
> shed some light to this!
>
> input program.
> vector v(20,f1).
> loop id = 1 to 10.
> loop #v = 1 to 20.
> compute v(#v)=rnd(rv.uniform(1,5)).
> end loop.
> end case.
> end loop.
> end file.
> end input program.
> exe.
>
> define !demo (vars=!charend('/')
>                     /number =!charend('/'))
> !let !counter=!blanks(0)
> !do !i !in (!vars)
>     !let !counter=!concat(!counter,!blanks(1))
>     title counter lengeth equals !len(!counter).
>     !if (!len(!counter) < !number) !then
>         freq !i.
>     !ifend
> !doend
> !enddefine.
> set printback on mprint on.
> !demo vars=V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
>                  V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 /number=3.
> set mprint off.
>
>

No idea why that's misbehaving.  But how about this as an alternative way
of
getting it done?  Notice that I changed your second !charend('/') to
!cmdend.  I also assume that you want to loop from 1 to !number, not to
!number-1.


define !demo (vars=!charend('/') /
              number =!cmdend)
!let !vcopy = !vars
!do !i = 1 !to !number
!let !v = !head(!vcopy)
!let !vcopy = !tail(!vcopy)
freq !v.
!doend
!enddefine.

set printback on mprint on.
!demo vars=V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
                 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 /number=3.
set mprint off.

HTH.



-----
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Operators-in-macro-tp3315178p3315424.html

Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (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
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: Operators in macro

Bruce Weaver
Administrator
I missed your !BREAK 'hack' earlier.  But yes, I like the !HEAD/!TAIL method for this.  

I was about to thank you for teaching me about !HEAD and !TAIL a few years back, but given the possible connotations, I decided I better not.  :-|

Cheers,
Bruce


David Marso wrote
Hi Bruce,
I'll bet that the !Len comparisons are also string compares.
"  !if (!len(!counter) !LE !len(!max)) !then    "
Hence my !BREAK 'hack'
I believe the !HEAD/!TAIL method you posted is far better than the original or my !BREAK 'hack'.
David

Bruce Weaver wrote
Hi Jon.  That occurred to me, so I tried this variation on the original macro:

define !demo (vars=!charend('/') /
              number =!cmdend)
!let !counter=!blanks(0)
!let !max = !blanks(!number)
!do !i !in (!vars)
    !let !counter=!concat(!counter,!blanks(1))
    title counter length equals !len(!counter).
    !if (!len(!counter) !LE !len(!max)) !then       <-- notice the change here
        freq !i.
    !ifend
!doend
!enddefine.


But it still did not work, and I'm not sure why.  Any thoughts?

bw


Jon K Peck wrote
As I told the user offline, the comparison is being made lexicographically
as strings, where "1" is less than "3".

Jon Peck
Senior Software Engineer, IBM
peck@us.ibm.com
312-651-3435



From:   Bruce Weaver <bruce.weaver@hotmail.com>
To:     SPSSX-L@LISTSERV.UGA.EDU
Date:   12/22/2010 10:49 AM
Subject:        Re: [SPSSX-L] Operators in macro
Sent by:        "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>



J Sutar wrote:
>
>  Hi there,
>
> I've simplified the macro to demonstrate the problem. I'm looping over a
> list of vars and concatenating blanks to keep a track of the loop number
> however it interprets 10 to be less than 3 (using the example below)?
>
> If I however change "*<*" to "*=*" in the line "*!if (!len(!counter) <
> !number) !then*" then it always interprets it correctly. Please can
> someone
> shed some light to this!
>
> input program.
> vector v(20,f1).
> loop id = 1 to 10.
> loop #v = 1 to 20.
> compute v(#v)=rnd(rv.uniform(1,5)).
> end loop.
> end case.
> end loop.
> end file.
> end input program.
> exe.
>
> define !demo (vars=!charend('/')
>                     /number =!charend('/'))
> !let !counter=!blanks(0)
> !do !i !in (!vars)
>     !let !counter=!concat(!counter,!blanks(1))
>     title counter lengeth equals !len(!counter).
>     !if (!len(!counter) < !number) !then
>         freq !i.
>     !ifend
> !doend
> !enddefine.
> set printback on mprint on.
> !demo vars=V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
>                  V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 /number=3.
> set mprint off.
>
>

No idea why that's misbehaving.  But how about this as an alternative way
of
getting it done?  Notice that I changed your second !charend('/') to
!cmdend.  I also assume that you want to loop from 1 to !number, not to
!number-1.


define !demo (vars=!charend('/') /
              number =!cmdend)
!let !vcopy = !vars
!do !i = 1 !to !number
!let !v = !head(!vcopy)
!let !vcopy = !tail(!vcopy)
freq !v.
!doend
!enddefine.

set printback on mprint on.
!demo vars=V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
                 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 /number=3.
set mprint off.

HTH.



-----
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Operators-in-macro-tp3315178p3315424.html

Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).