Date: Sat, 4 Dec 2004 18:34:07 +0200
Reply-To: Martins.Liberts@csb.gov.lv
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Martins Liberts <Martins.Liberts@csb.gov.lv>
Subject: Defining macro values in a loop
Content-Type: text/plain; charset="us-ascii"
Hi listers,
The question is how to repeatedly run the syntax by changing the values of
macros in each run?
I will try to give an example.
There is a macro witch defines the number of month (I will call it
"parameter macro"):
define !mon() 5 !enddefine.
There is another macros who converts the number of month to two digit
number (I will call it "techical macro"):
define !mon2() !sub(!con("0",!eva(!mon)),!len(!eva(!mon)),2) !enddefine.
There are several such "parameter macros" and lot of "technical macros".
After defining all macros there comes data transformation using the
macros. In result I will get the estimations. So by changing value of
macro !mon I can get the estimate of each month.
Now I want to run all these procedures for example 12 month.
***.
First idea was to define new macro, where the value of !mon will be
changed in !do-!doend cycle, the transformations will be included and
results saved. There is a small example:
define !temp2()
!do !men=1 !to 12
!mon2
!doend
!enddefine.
But it fails. The result:
!temp2
7034 M> 05
7035 M> 05
7036 M> 05
7037 M> 05
7038 M> 05
7039 M> 05
7040 M> 05
7041 M> 05
7042 M> 05
7043 M> 05
7044 M> 05
7045 M> 05
The !mon2 doesn't use the value from !do-!doend cycle.
***.
The second idea is to change the definition of !mon2 by adding an argument
to it.
define !mon3(!pos !tok(1))
!sub(!con("0",!eva(!1)),!len(!eva(!1)),2)
!enddefine.
So !mon3 requires the argument where the number of month will be given. So
there is another macro:
define !temp3()
!do !mon=1 !to 12
!mon3 !mon
!doend
!enddefine.
And it works. Results:
!temp3
7074 M> 01
7075 M> 02
7076 M> 03
7077 M> 04
7078 M> 05
7079 M> 06
7080 M> 07
7081 M> 08
7082 M> 09
7083 M> 10
7084 M> 11
7085 M> 12
So probaly it would be wise to use more arguments by defining macros. The
argument makes macro comands more flexable. So to make it work I have to
redefine all "technical macros" and make changes in transformations by
adding necesery arguments to macro comands. Probably this is not good idea
because it will make the syntax of transformations more complex
--
Martins Liberts
Central Statistical Bureau of Latvia
address: Lacplesa iela 1, Riga, LV-1301, Latvia
phone: 371-7366877
email: Martins.Liberts@csb.gov.lv