assigning value to macro variable

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

assigning value to macro variable

Albert-Jan Roskam
Hi list,

I would like to assign a value to a macro variable.
This value is derived from a data set. In the example
below, I would like to assign the maximum age to a
macro variable '!max_age'. Obviously this does not
work, although the syntax generates no errors. Is it
possible to do this, e.g. to assign a value to a macro
variable in a data-driven way? I am looking for
something similar to CALL SYMPUT in SAS.

Does anybody have suggestions? I am using Neolithic
SPSS v11 --ahem!

Best wishes,
Albert-Jan

**************.
*** generation of sample data set.
input program.
loop #i = 1 to 100.
compute age = rnd(rv.uniform(25,90)).
compute sex = 2.
if #i le 50 sex = 1.
end case.
end loop.
end file.
end input program.
exe.

** the actual question.
aggregate / outfile = * / break = sex / mymax 'highest
age' = max (age).

set mprint = yes.

define testme ().
!if ($casenum = 1) !then.
!let !max_age = mymax.
!ifend.
title !quote(!concat('*does it work? -->*',!max_age)).

!enddefine.

testme.

Cheers!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Did you know that 87.166253% of all statistics claim a precision of results that is not justified by the method employed? [HELMUT RICHTER]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



____________________________________________________________________________________
Need a quick answer? Get one in minutes from people who know.
Ask your question on www.Answers.yahoo.com
Reply | Threaded
Open this post in threaded view
|

AW: assigning value to macro variable

la volta statistics
Hi Albert-Jan

try the following:


* Start syntax.
input program.
loop #i = 1 to 100.
compute age = rnd(rv.uniform(25,90)).
compute sex = 2.
if #i le 50 sex = 1.
end case.
end loop.
end file.
end input program.
exe.

** the actual question.
aggregate / outfile = * / break = sex
 / mymax 'highest age' = max (age).

set mprint = yes.

* Do formating here (if you want).
*Format myMax (F8.0).

DO IF $CASENUM = 1.
WRITE OUTFILE "C:\Temp\MyAge.sps"/"DEFINE !Max_Age ()"/myMax
/"!ENDDEFINE."/"Exec.".
END IF.
Exec.

INSERT  FILE =  "C:\Temp\MyAge.sps".

define testme ().
title !quote(!concat('*does it work? -->*',!EVAL(!max_age))).
!enddefine.

testme.

* End syntax.

Hope that helps
Christian

-----Ursprüngliche Nachricht-----
Von: SPSSX(r) Discussion [mailto:[hidden email]]Im Auftrag von
Albert-jan Roskam
Gesendet: Montag, 19. Februar 2007 14:02
An: [hidden email]
Betreff: assigning value to macro variable


Hi list,

I would like to assign a value to a macro variable.
This value is derived from a data set. In the example
below, I would like to assign the maximum age to a
macro variable '!max_age'. Obviously this does not
work, although the syntax generates no errors. Is it
possible to do this, e.g. to assign a value to a macro
variable in a data-driven way? I am looking for
something similar to CALL SYMPUT in SAS.

Does anybody have suggestions? I am using Neolithic
SPSS v11 --ahem!

Best wishes,
Albert-Jan

**************.
*** generation of sample data set.
input program.
loop #i = 1 to 100.
compute age = rnd(rv.uniform(25,90)).
compute sex = 2.
if #i le 50 sex = 1.
end case.
end loop.
end file.
end input program.
exe.

** the actual question.
aggregate / outfile = * / break = sex / mymax 'highest
age' = max (age).

set mprint = yes.

define testme ().
!if ($casenum = 1) !then.
!let !max_age = mymax.
!ifend.
title !quote(!concat('*does it work? -->*',!max_age)).

!enddefine.

testme.

Cheers!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Did you know that 87.166253% of all statistics claim a precision of results
that is not justified by the method employed? [HELMUT RICHTER]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Need a quick answer? Get one in minutes from people who know.
Ask your question on www.Answers.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: AW: assigning value to macro variable

Albert-Jan Roskam
hi Christian,

Thank you! Nice to use a self-writing syntax for this;
I've hardly ever used those. After two minor
adjustments it worked!
INSERT does not exist In v11, I used INCLUDE instead.
Next, I omitted the exclamation mark in the nested
macro. I've experienced before that that does not work
in 'nested' syntaxes.

Below is the syntax, which I intend to use to
dynamically assign upper age limits.


* Start syntax.
input program.
loop #i = 1 to 100.
compute age = rnd(rv.uniform(25,90)).
compute sex = 2.
if #i le 50 sex = 1.
end case.
end loop.
end file.
end input program.
exe.

save outfile = 'd:\temp\try.sav'.

** the actual question.
aggregate / outfile = * / break = sex
 / mymax 'highest age' = max (age).

set mprint = yes.

* Do formating here (if you want).
*Format myMax (F8.0).

DO IF $CASENUM = 1.
WRITE OUTFILE "C:\Temp\MyAge.sps"/"DEFINE Max_Age
()"/myMax
/"!ENDDEFINE."/"Exec.".
END IF.
Exec.

include  FILE =  "C:\Temp\MyAge.sps".

define testme ().
title !quote(!concat('*does it work?
-->*',!EVAL(max_age))).
get file = 'd:\temp\try.sav'.
select if age le !eval(max_age).
!enddefine.

testme.




--- la volta statistics <[hidden email]>
wrote:

> Hi Albert-Jan
>
> try the following:
>
>
> * Start syntax.
> input program.
> loop #i = 1 to 100.
> compute age = rnd(rv.uniform(25,90)).
> compute sex = 2.
> if #i le 50 sex = 1.
> end case.
> end loop.
> end file.
> end input program.
> exe.
>
> ** the actual question.
> aggregate / outfile = * / break = sex
>  / mymax 'highest age' = max (age).
>
> set mprint = yes.
>
> * Do formating here (if you want).
> *Format myMax (F8.0).
>
> DO IF $CASENUM = 1.
> WRITE OUTFILE "C:\Temp\MyAge.sps"/"DEFINE !Max_Age
> ()"/myMax
> /"!ENDDEFINE."/"Exec.".
> END IF.
> Exec.
>
> INSERT  FILE =  "C:\Temp\MyAge.sps".
>
> define testme ().
> title !quote(!concat('*does it work?
> -->*',!EVAL(!max_age))).
> !enddefine.
>
> testme.
>
> * End syntax.
>
> Hope that helps
> Christian
>
> -----Urspr�ngliche Nachricht-----
> Von: SPSSX(r) Discussion
> [mailto:[hidden email]]Im Auftrag von
> Albert-jan Roskam
> Gesendet: Montag, 19. Februar 2007 14:02
> An: [hidden email]
> Betreff: assigning value to macro variable
>
>
> Hi list,
>
> I would like to assign a value to a macro variable.
> This value is derived from a data set. In the
> example
> below, I would like to assign the maximum age to a
> macro variable '!max_age'. Obviously this does not
> work, although the syntax generates no errors. Is it
> possible to do this, e.g. to assign a value to a
> macro
> variable in a data-driven way? I am looking for
> something similar to CALL SYMPUT in SAS.
>
> Does anybody have suggestions? I am using Neolithic
> SPSS v11 --ahem!
>
> Best wishes,
> Albert-Jan
>
> **************.
> *** generation of sample data set.
> input program.
> loop #i = 1 to 100.
> compute age = rnd(rv.uniform(25,90)).
> compute sex = 2.
> if #i le 50 sex = 1.
> end case.
> end loop.
> end file.
> end input program.
> exe.
>
> ** the actual question.
> aggregate / outfile = * / break = sex / mymax
> 'highest
> age' = max (age).
>
> set mprint = yes.
>
> define testme ().
> !if ($casenum = 1) !then.
> !let !max_age = mymax.
> !ifend.
> title !quote(!concat('*does it work?
> -->*',!max_age)).
>
> !enddefine.
>
> testme.
>
> Cheers!
> Albert-Jan
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Did you know that 87.166253% of all statistics claim
> a precision of results
> that is not justified by the method employed?
> [HELMUT RICHTER]
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
>
> Need a quick answer? Get one in minutes from people
> who know.
> Ask your question on www.Answers.yahoo.com
>


Cheers!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Did you know that 87.166253% of all statistics claim a precision of results that is not justified by the method employed? [HELMUT RICHTER]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




____________________________________________________________________________________
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
http://answers.yahoo.com/dir/?link=list&sid=396546091
Reply | Threaded
Open this post in threaded view
|

Re: assigning value to macro variable

Peck, Jon
In reply to this post by Albert-Jan Roskam
It won’t help with SPSS 11, but with programmability in SPSS 14 or later, you can define macro values very generally.  In the spss module, there is a function called

SetMacroValue(name, value)

that can be used to define a macro whose value is anything you can compute, including functions of the data and properties of the variable dictionary.

These macros can then be used in subsequent SPSS syntax.

-Jon Peck

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Albert-jan Roskam
Sent: Monday, February 19, 2007 7:02 AM
To: [hidden email]
Subject: [SPSSX-L] assigning value to macro variable

Hi list,

I would like to assign a value to a macro variable.
This value is derived from a data set. In the example
below, I would like to assign the maximum age to a
macro variable '!max_age'. Obviously this does not
work, although the syntax generates no errors. Is it
possible to do this, e.g. to assign a value to a macro
variable in a data-driven way? I am looking for
something similar to CALL SYMPUT in SAS.

Does anybody have suggestions? I am using Neolithic
SPSS v11 --ahem!

Best wishes,
Albert-Jan