How to do addition in SPSS macro

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

How to do addition in SPSS macro

jagadishpchary
This post was updated on .
Hi:

Might be it is a easy one. However I am unable to find the solution. Actually I am looking for a syntax in Macro where I have to add two passing variable i.e.

!LET !f = Sum (!ARG1,!ARG2)
OR
!LET !f = !ARG1 + !ARG2

the above syntax's are not working. So can any one let me know the correct/workable solution for my query.

Note: No new variables should be created in this process.

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: How to do addition in SPSS macro

Jignesh Sutar
You would think it would be an easy one (I'm sure there is plenty of posts on this subject in the archives)...

Can't get a more comprehensive guide on this than:

http://spsstools.net/de/plaintext/ArithmeticWithMacroVariables.txt/

Reply | Threaded
Open this post in threaded view
|

Re: How to do addition in SPSS macro

Jon Peck
In reply to this post by jagadishpchary
The best solution is to use Python programmability for this sort of thing.

On Tue, Jan 19, 2016 at 9:03 AM, jagadishpchary <[hidden email]> wrote:
Hi:

Might be it is a easy one. However I am unable to find the solution.
Actually I am looking for a syntax in Macro where I have to add two passing
variable i.e.

!LET !f = Sum (!ARG1,!ARG2)
OR
!LET !f = !ARG1 + !ARG2

the above syntax's are not working. So can any one let me know the
correct/workable solution for my query.

Thanks.



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-do-addition-in-SPSS-macro-tp5731341.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



--
Jon K Peck
[hidden email]

===================== 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: How to do addition in SPSS macro

David Marso
Administrator
In reply to this post by Jignesh Sutar
"/* This code cannot be encapsulated in macros called from other macros. This
/* is because assignments such as  "!let !a = !add(6,2)"  do not work; SPSS
/* will not recognize any tokens following the macro name "!add"."

Not to be a contrarian or anything but the above is REALLY not the case if you think about it a bit  or maybe a lot? or way too much, ( certainly helps to be a bit mad ;-))).
I posted code on MACRO return values sometime last year (or was it the year previous?).
----
SET MPRINT ON PRINTBACK ON.
DEFINE !Add (!POS !TOKENS(1) /!POS !TOKENS(1)/!POS !TOKENS(1))
!SUBSTR(!UNQUOTE(!3),3) !LENGTH(  !CONCAT( !BLANKS(!1),!BLANKS(!2)  ) ) .
!ENDDEFINE.


DEFINE !Caller (!POS !TOKENS(1))
!IF (!1 !EQ ?) !THEN
!ADD 1 3 '/*!Caller' .
!ELSE
ECHO 'In Main'.
ECHO !QUOTE(!1).
!IFEND
!ENDDEFINE.

!Caller ? .




Jignesh Sutar wrote
You would think it would be an easy one (I'm sure there is plenty of posts on this subject in the archives)...

Can't get a more comprehensive guide on this than:

http://spsstools.net/de/plaintext/ArithmeticWithMacroVariables.txt/
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?"