Help with another SPSS macro

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

Help with another SPSS macro

Ratna Wynn

Hi

 

I need a bit more help with another SPSS macro. I am trying to create a macro that will accept variables to be summed. The macro has two arguments - the first the variable name for the sum function and the second is the variables to be summed. I want to keep the number of variables entered dynamic.

The macro code runs with errors but when I call the macro it give me an error that I cannot figure out. The error says

 

"Text: !sumstrs3
>The expression is incomplete. Check for missing operands, invalid operators,
>unmatched parentheses or excessive string length.
>This command not executed.

"

 

 

Define !sumval (!positional !token(1) /!positional !cmdend)

!LET !YCOPY=!2

!LET !firstvar = !HEAD(!YCOPY)

!LET !YCOPY=!TAIL(!YCOPY)

!let !test=!null

 

!DO !x !IN (!ycopy)

!LET !sumfun= !concat(!HEAD(!YCOPY),",")

!let !test=!concat(!test, !sumfun)

!LET !YCOPY=!TAIL(!YCOPY)

!doend

!let !sumarg=!concat(!test, !firstvar).

compute !1=sum(!sumarg).

fre !1 /sta mean.

!enddefine.

 

!sumfunction s3s4s5_sum s4 s5 s3.

 

Thanks in advance!

 

Ratna

 

Ratna Wynn

 

Reply | Threaded
Open this post in threaded view
|

Re: Help with another SPSS macro

Bruce Weaver
Administrator
Why not just use a simple COMPUTE statement, such as:

COMPUTE s3s4s5_sum = SUM(s4, s5, s3).

As far as I can see, the macro has NO advantage over this.  



Ratna Wynn wrote
Hi



I need a bit more help with another SPSS macro. I am trying to create a
macro that will accept variables to be summed. The macro has two arguments -
the first the variable name for the sum function and the second is the
variables to be summed. I want to keep the number of variables entered
dynamic.

The macro code runs with errors but when I call the macro it give me an
error that I cannot figure out. The error says



"Text: !sumstrs3
>The expression is incomplete. Check for missing operands, invalid
operators,
>unmatched parentheses or excessive string length.
>This command not executed.

"





Define !sumval (!positional !token(1) /!positional !cmdend)

!LET !YCOPY=!2

!LET !firstvar = !HEAD(!YCOPY)

!LET !YCOPY=!TAIL(!YCOPY)

!let !test=!null



!DO !x !IN (!ycopy)

!LET !sumfun= !concat(!HEAD(!YCOPY),",")

!let !test=!concat(!test, !sumfun)

!LET !YCOPY=!TAIL(!YCOPY)

!doend

!let !sumarg=!concat(!test, !firstvar).

compute !1=sum(!sumarg).

fre !1 /sta mean.

!enddefine.



!sumfunction s3s4s5_sum s4 s5 s3.



Thanks in advance!



Ratna



Ratna Wynn


--
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/).