Macro trouble

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

Macro trouble

Ruben Geert van den Berg
Dear all,
 
Could anybody please tell me why this is not working?
 
define !SIM (file=!tok(1)/dep=!tok(1)/ind=!cha('/')
/depco=!tok(1)!default(neg)/indco=!tok(1)!default(neg)
/depwn=!tok(1)!default(6)/indwn=!tok(1)!default(6)
/indsca=!tok(1)!default(5))
set mpr on.
datas nam data.
mis val !dep(!depwn)!ind(!indwn).
 
<rest of macro body>
 

!SIM(file=sim1 dep=V10031_1 ind= V10031_2 V10031_3 V10031_5 V10032_8 V10032_12 V10032_13/).

1688 0 M>

1689 0 M> .

1690 0 M> set mpr on.

1691 0 M> datas nam data.

1692 0 M> mis val ( 6 ) ( 6 ).

 

I mean, why does it leave !dep and !ind blanks? Why doesn't it fill in the variables I specified on my macro call?

 

TIA!

 

Ruben





 





New Windows 7: Find the right PC for you. Learn more.
Reply | Threaded
Open this post in threaded view
|

Re: Macro trouble

Albert-Jan Roskam
Hi Ruben,
 
Not sure why it doesn't work, but in my dictionary, under "macro", it says "see also: 'trouble'." ;-) The macro facility is just quite quirky with certain things. The code below does work:
 
begin program.
import spss
def sim (file, dep, ind, depco=1, indco=1, depwn=6, indwn=6, indsca=5):
  spss.Submit("""set mpr on.
dataset name data.
missing values %(dep)s (%(depwn)s) %(ind)s (%(indwn)s).""" % locals())
sim(file="somefile.sav", dep="id", ind="gender")
end program.

ps: I'd change the function name to something more meaning full. One convention is to include a verb in the imperative tense.

Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the face of ambiguity, refuse the temptation to guess.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Mon, 12/14/09, Ruben van den Berg <[hidden email]> wrote:

From: Ruben van den Berg <[hidden email]>
Subject: [SPSSX-L] Macro trouble
To: [hidden email]
Date: Monday, December 14, 2009, 2:27 PM

Dear all,
 
Could anybody please tell me why this is not working?
 
define !SIM (file=!tok(1)/dep=!tok(1)/ind=!cha('/')
/depco=!tok(1)!default(neg)/indco=!tok(1)!default(neg)
/depwn=!tok(1)!default(6)/indwn=!tok(1)!default(6)
/indsca=!tok(1)!default(5))
set mpr on.
datas nam data.
mis val !dep(!depwn)!ind(!indwn).
 
<rest of macro body>
 

!SIM(file=sim1 dep=V10031_1 ind= V10031_2 V10031_3 V10031_5 V10032_8 V10032_12 V10032_13/).

1688 0 M>

1689 0 M> .

1690 0 M> set mpr on.

1691 0 M> datas nam data.

1692 0 M> mis val ( 6 ) ( 6 ).

 

I mean, why does it leave !dep and !ind blanks? Why doesn't it fill in the variables I specified on my macro call?

 

TIA!

 

Ruben





 





New Windows 7: Find the right PC for you. Learn more.

Reply | Threaded
Open this post in threaded view
|

Re: Macro trouble

Ruben Geert van den Berg
Thanks, Albert-Jan!
 
Can python macros accomplish anything that 'define' can?
 
As far as the name is concerned: SIM = Strategic Improvement Matrix, very well known among my colleagues who will -hopefully at some point- use this macro.
 
With regard to the code, I've discovered my own stupidity this time:

Wrong way:

!SIM(file=sim1 dep=V10031_1 ind= V10031_2 V10031_3 V10031_5 V10032_8 V10032_12 V10032_13/).


Right way:
 

!SIMfile=sim1 dep=V10031_1 ind= V10031_2 V10031_3 V10031_5 V10032_8 V10032_12 V10032_13/.


CHEERS!!
 
Ruben van den Berg



 

Date: Mon, 14 Dec 2009 06:16:08 -0800
From: [hidden email]
Subject: Re: Macro trouble
To: [hidden email]

Hi Ruben,
 
Not sure why it doesn't work, but in my dictionary, under "macro", it says "see also: 'trouble'." ;-) The macro facility is just quite quirky with certain things. The code below does work:
 
begin program.
import spss
def sim (file, dep, ind, depco=1, indco=1, depwn=6, indwn=6, indsca=5):
  spss.Submit("""set mpr on.
dataset name data.
missing values %(dep)s (%(depwn)s) %(ind)s (%(indwn)s).""" % locals())
sim(file="somefile.sav", dep="id", ind="gender")
end program.

ps: I'd change the function name to something more meaning full. One convention is to include a verb in the imperative tense.

Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the face of ambiguity, refuse the temptation to guess.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Mon, 12/14/09, Ruben van den Berg <[hidden email]> wrote:

From: Ruben van den Berg <[hidden email]>
Subject: [SPSSX-L] Macro trouble
To: [hidden email]
Date: Monday, December 14, 2009, 2:27 PM

Dear all,
 
Could anybody please tell me why this is not working?
 
define !SIM (file=!tok(1)/dep=!tok(1)/ind=!cha('/')
/depco=!tok(1)!default(neg)/indco=!tok(1)!default(neg)
/depwn=!tok(1)!default(6)/indwn=!tok(1)!default(6)
/indsca=!tok(1)!default(5))
set mpr on.
datas nam data.
mis val !dep(!depwn)!ind(!indwn).
 
<rest of macro body>
 

!SIM(file=sim1 dep=V10031_1 ind= V10031_2 V10031_3 V10031_5 V10032_8 V10032_12 V10032_13/).

1688 0 M>

1689 0 M> .

1690 0 M> set mpr on.

1691 0 M> datas nam data.

1692 0 M> mis val ( 6 ) ( 6 ).

 

I mean, why does it leave !dep and !ind blanks? Why doesn't it fill in the variables I specified on my macro call?

 

TIA!

 

Ruben





 





New Windows 7: Find the right PC for you. Learn more.



New Windows 7: Simplify what you do everyday. Find the right PC for you.
Reply | Threaded
Open this post in threaded view
|

Re: Macro trouble

ViAnn Beadle

Python is much more powerful than macros. It is data aware. That is, it can be used to fetch dictionary information such as variable names, formats, and labels; and it can be used to read data stored in those variables. Take a look at the documentation and examples on http://www.spss.com/devcentral/.

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Ruben van den Berg
Sent: Monday, December 14, 2009 8:17 AM
To: [hidden email]
Subject: Re: Macro trouble

 

Thanks, Albert-Jan!
 
Can python macros accomplish anything that 'define' can?
 
As far as the name is concerned: SIM = Strategic Improvement Matrix, very well known among my colleagues who will -hopefully at some point- use this macro.
 
With regard to the code, I've discovered my own stupidity this time:

Wrong way:

!SIM(file=sim1 dep=V10031_1 ind= V10031_2 V10031_3 V10031_5 V10032_8 V10032_12 V10032_13/).


Right way:
 

!SIMfile=sim1 dep=V10031_1 ind= V10031_2 V10031_3 V10031_5 V10032_8 V10032_12 V10032_13/.


CHEERS!!
 
Ruben van den Berg



 


Date: Mon, 14 Dec 2009 06:16:08 -0800
From: [hidden email]
Subject: Re: Macro trouble
To: [hidden email]

Hi Ruben,

 

Not sure why it doesn't work, but in my dictionary, under "macro", it says "see also: 'trouble'." ;-) The macro facility is just quite quirky with certain things. The code below does work:

 

begin program.

import spss

def sim (file, dep, ind, depco=1, indco=1, depwn=6, indwn=6, indsca=5):

  spss.Submit("""set mpr on.

dataset name data.

missing values %(dep)s (%(depwn)s) %(ind)s (%(indwn)s).""" % locals())

sim(file="somefile.sav", dep="id", ind="gender")

end program.


ps: I'd change the function name to something more meaning full. One convention is to include a verb in the imperative tense.


Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the face of ambiguity, refuse the temptation to guess.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Mon, 12/14/09, Ruben van den Berg <[hidden email]> wrote:


From: Ruben van den Berg <[hidden email]>
Subject: [SPSSX-L] Macro trouble
To: [hidden email]
Date: Monday, December 14, 2009, 2:27 PM

Dear all,
 
Could anybody please tell me why this is not working?
 
define !SIM (file=!tok(1)/dep=!tok(1)/ind=!cha('/')
/depco=!tok(1)!default(neg)/indco=!tok(1)!default(neg)
/depwn=!tok(1)!default(6)/indwn=!tok(1)!default(6)
/indsca=!tok(1)!default(5))
set mpr on.
datas nam data.
mis val !dep(!depwn)!ind(!indwn).
 
<rest of macro body>
 

!SIM(file=sim1 dep=V10031_1 ind= V10031_2 V10031_3 V10031_5 V10032_8 V10032_12 V10032_13/).

1688 0 M>

1689 0 M> .

1690 0 M> set mpr on.

1691 0 M> datas nam data.

1692 0 M> mis val ( 6 ) ( 6 ).

 

I mean, why does it leave !dep and !ind blanks? Why doesn't it fill in the variables I specified on my macro call?

 

TIA!

 

Ruben





 




New Windows 7: Find the right PC for you. Learn more.

 


New Windows 7: Simplify what you do everyday. Find the right PC for you.

Reply | Threaded
Open this post in threaded view
|

Re: Macro trouble

Albert-Jan Roskam
In reply to this post by Ruben Geert van den Berg
You're welcome! Yep, Python functions can do the same as Spss macros +  a whole lot more. I find the notation a lot easier (think of the endless nested !quote !concats). And many things cannot (or hardly) be done using the macro facility. For instance, it's easy to do arithmetic with e.g. loop indexes. Or to time stamp a file, etc. etc. "De keuze is reuze!"
;-)

Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the face of ambiguity, refuse the temptation to guess.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Mon, 12/14/09, Ruben van den Berg <[hidden email]> wrote:

From: Ruben van den Berg <[hidden email]>
Subject: Re: [SPSSX-L] Macro trouble
To: [hidden email]
Date: Monday, December 14, 2009, 4:16 PM

Thanks, Albert-Jan!
 
Can python macros accomplish anything that 'define' can?
 
As far as the name is concerned: SIM = Strategic Improvement Matrix, very well known among my colleagues who will -hopefully at some point- use this macro.
 
With regard to the code, I've discovered my own stupidity this time:

Wrong way:

!SIM(file=sim1 dep=V10031_1 ind= V10031_2 V10031_3 V10031_5 V10032_8 V10032_12 V10032_13/).


Right way:
 

!SIMfile=sim1 dep=V10031_1 ind= V10031_2 V10031_3 V10031_5 V10032_8 V10032_12 V10032_13/.
CHEERS!!
 
Ruben van den Berg



 


Date: Mon, 14 Dec 2009 06:16:08 -0800
From: [hidden email]
Subject: Re: Macro trouble
To: [hidden email]

Hi Ruben,
 
Not sure why it doesn't work, but in my dictionary, under "macro", it says "see also: 'trouble'." ;-) The macro facility is just quite quirky with certain things. The code below does work:
 
begin program.
import spss
def sim (file, dep, ind, depco=1, indco=1, depwn=6, indwn=6, indsca=5):
  spss.Submit("""set mpr on.
dataset name data.
missing values %(dep)s (%(depwn)s) %(ind)s (%(indwn)s).""" % locals())
sim(file="somefile.sav", dep="id", ind="gender")
end program.

ps: I'd change the function name to something more meaning full. One convention is to include a verb in the imperative tense.

Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the face of ambiguity, refuse the temptation to guess.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Mon, 12/14/09, Ruben van den Berg <[hidden email]> wrote:

From: Ruben van den Berg <[hidden email]>
Subject: [SPSSX-L] Macro trouble
To: [hidden email]
Date: Monday, December 14, 2009, 2:27 PM

Dear all,
 
Could anybody please tell me why this is not working?
 
define !SIM (file=!tok(1)/dep=!tok(1)/ind=!cha('/')
/depco=!tok(1)!default(neg)/indco=!tok(1)!default(neg)
/depwn=!tok(1)!default(6)/indwn=!tok(1)!default(6)
/indsca=!tok(1)!default(5))
set mpr on.
datas nam data.
mis val !dep(!depwn)!ind(!indwn).
 
<rest of macro body>
 

!SIM(file=sim1 dep=V10031_1 ind= V10031_2 V10031_3 V10031_5 V10032_8 V10032_12 V10032_13/).

1688 0 M>

1689 0 M> .

1690 0 M> set mpr on.

1691 0 M> datas nam data.

1692 0 M> mis val ( 6 ) ( 6 ).

 

I mean, why does it leave !dep and !ind blanks? Why doesn't it fill in the variables I specified on my macro call?

 

TIA!

 

Ruben





 





New Windows 7: Find the right PC for you. Learn more.



New Windows 7: Simplify what you do everyday. Find the right PC for you.