How to generalize syntax?

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

How to generalize syntax?

Gyorgy Bea
Hi,

I would like to generalize the following syntax, I believe it is possible to do it with macro or python, but I'm very new in both. Could you suggest a way to start?
The syntax looks for the minimum value in a set of variables (v1 to v7) and stores it in Qnew1: if there is any value in my variables (if Qcount>0) records the first not empty variable (compute #min=v(#n)), and compares it to the other variables to find the minimum.
This works fine, but I have to repeat the same procedure for different sets of variables:

Variables        No.Variables            Count             Minimum
v1 to v7             7                        Qcount1            Qnew1
v8 to v10           3                        Qcount2            Qnew2
v11 to v14         4                        Qcount3            Qnew3
....                    ...                        ...                    ...
v(xn) to v(xn+5)  6                        QcountX           QnewX        
   

vector v=v1 to v7.
do if Qcount1>0.
   compute #n=0.
   loop. 
      compute #n=#n+1.
   end loop if (not missing(v(#n)) or #n=7).
   compute #min=v(#n).
   loop #i=#n+1 to 7.
      do if (not missing(v(#i)) and #min>v(#i)).
         compute #min=v(#i).
      end if.
   end loop.
   compute Qnew1=#min.
end if.
exe.


Any idea is very welcome!

Thanks a lot,
Beata

Reply | Threaded
Open this post in threaded view
|

Re: How to generalize syntax?

Richard Ristow
At 05:12 AM 4/1/2009, Gyorgy Bea wrote:

>[This loop] syntax looks for the minimum value in a set of variables
>(v1 to v7) and stores it in Qnew1: if there is any value in my
>variables (if Qcount>0) records the first not empty variable
>(compute #min=v(#n)), and compares it to the other variables to find
>the minimum.

Does the following do what you want? (Not tested)

COMPUTE Qcount = NVALID(v1 to v7).
COMPUTE Qnew1  = MAX(v1 to v7).

=====================
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