Count number of variables in list

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

Count number of variables in list

vlad simion
Hi,

I have a list of variables as a macro argument. I want to count the number
of variables in list and then pass it on as a macro argument.
Does anyone have any suggestions?
Many thanks!

Vlad.


--
Vlad Simion
Data Analyst
Tel:      +40 720130611
Reply | Threaded
Open this post in threaded view
|

Re: Count number of variables in list

Spousta Jan
Hi Vlad,

Use Python if you can.

If you cannot, use an old trick I know from Raynald Levesque: in a !DO
loop, add one character for a variable to a string, and then measure
!LENGTH of the string after the loop ends. Very awkward, but does work.

HTH

Jan


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
vlad simion
Sent: Friday, September 08, 2006 3:57 PM
To: [hidden email]
Subject: Count number of variables in list

Hi,

I have a list of variables as a macro argument. I want to count the
number of variables in list and then pass it on as a macro argument.
Does anyone have any suggestions?
Many thanks!

Vlad.


--
Vlad Simion
Data Analyst
Tel:      +40 720130611
Reply | Threaded
Open this post in threaded view
|

Re: Count number of variables in list

Antro, Mark
In reply to this post by vlad simion
Hi Vlad,

Why so you need to know the number of variables? If it's to loop through them, then use the...

!DO !v !IN (!Varlist)

!DOEND

structure, where !v will take on the variables one by one from the list you supply to the macro argument !Varlist

If you need the number for something else let me know, or try this...

!LET !string = "".
!DO !I !IN (!CAT)
!LET !string = !CONCAT(!string, "a").
!DOEND

The number of variables is returned by !LENGTH(!string).

Rgds
Antro.