f



macro to count variables

Hi all,
I have a little macro that performs a series of regression analyses
that I have to run repeatedly. The macro accommodates a variable
number of variables, but the user has to count and input this number
into the macro.

I was wondering if there is a way using the count command to
automatically count the number of variables inputted in the macro and
then fill in the number needed.

The macro call is like this, where users put in outcome variables,
predictor variables (as many as wished), and then they need to specify
the number of x's.

REGS y = dv /x = iv /n = nums.
***Then long macro goes here****.

I tried to count the x's using something like this (which I found at
http://web.uvic.ca/~cass/spss-macros.html):

DEFINE @CNTVAR@  (@VARS@ !ENCLOSE('(',')') /  @CNTVR@ !TOKENS(1) )
COUNT !@CNTVR@ =!@VARS@ (LO THRU HI,MISSING).
!ENDDEFINE .
@CNTVAR@ @VARS@ ( A B C ) @CNTVR@=N_ABC .
FREQ N_ABC .

But I don't know how to feed something like this back into the macro
specification.

My only solution might be to rebuild the macro so that it doesn't need
the number directly inputted, but it would be sweet if I could just
count the inputs, store that number in a macro variable, and then put
that into the macro call.

Any help or comment is appreciated.
Felize
0
felize
11/9/2009 3:54:16 PM
comp.soft-sys.stat.spss 5679 articles. 0 followers. Post Follow

4 Replies
555 Views

Similar Articles

[PageSpeed] 13

On Nov 9, 10:54=A0am, felize <felixthoem...@gmail.com> wrote:
> Hi all,
> I have a little macro that performs a series of regression analyses
> that I have to run repeatedly. The macro accommodates a variable
> number of variables, but the user has to count and input this number
> into the macro.
>
> I was wondering if there is a way using the count command to
> automatically count the number of variables inputted in the macro and
> then fill in the number needed.
>
> The macro call is like this, where users put in outcome variables,
> predictor variables (as many as wished), and then they need to specify
> the number of x's.
>
> REGS y =3D dv /x =3D iv /n =3D nums.
> ***Then long macro goes here****.
>
> I tried to count the x's using something like this (which I found athttp:=
//web.uvic.ca/~cass/spss-macros.html):
>
> DEFINE @CNTVAR@ =A0(@VARS@ !ENCLOSE('(',')') / =A0@CNTVR@ !TOKENS(1) )
> COUNT !@CNTVR@ =3D!@VARS@ (LO THRU HI,MISSING).
> !ENDDEFINE .
> @CNTVAR@ @VARS@ ( A B C ) @CNTVR@=3DN_ABC .
> FREQ N_ABC .
>
> But I don't know how to feed something like this back into the macro
> specification.
>
> My only solution might be to rebuild the macro so that it doesn't need
> the number directly inputted, but it would be sweet if I could just
> count the inputs, store that number in a macro variable, and then put
> that into the macro call.
>
> Any help or comment is appreciated.
> Felize

I think I would re-write the macro so that it doesn't need the number
of explanatory variables passed to it.  Does this do what you want?


define REGS (y =3D !tokens(1) / x =3D !CMDEND)

REGRESSION
  /MISSING LISTWISE
  /STATISTICS COEFF OUTS CI(95) R ANOVA
  /CRITERIA=3DPIN(.05) POUT(.10)
  /NOORIGIN
  /DEPENDENT !Y
  /METHOD=3DENTER !X.

!enddefine.


REGS y =3D DV  x =3D  x1 .
REGS y =3D DV  x =3D  x1 x2 .
REGS y =3D DV  x =3D  x1 x2 x3 .

--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/Home
"When all else fails, RTFM."
0
Bruce
11/9/2009 9:44:21 PM
Thanks for the comment Bruce.
I was afraid that changing the macro might be the way to go.
Unfortunately it is really long...
I guess I will have to try anyway as opposed to botching together some
work-around that counts some variables based on user input.
Thanks again for the comment.
0
felize
11/10/2009 5:18:09 PM
On Nov 10, 12:18=A0pm, felize <felixthoem...@gmail.com> wrote:
> Thanks for the comment Bruce.
> I was afraid that changing the macro might be the way to go.
> Unfortunately it is really long...
> I guess I will have to try anyway as opposed to botching together some
> work-around that counts some variables based on user input.
> Thanks again for the comment.

So presumably your macro does more than just run a regression model.
What else does it do, and do any of those other things require the
count of explanatory variables?  Is it a linear regression model, or
some other kind of regression?  If you give a bit more detail, perhaps
someone can provide a little more help.

--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/Home
"When all else fails, RTFM."
0
Bruce
11/10/2009 7:48:10 PM
The macro basically computes mediated effects as defined by Baron and
Kenny and computes a product term of regression coefficients and
applies a statistical test to them using Sobel's standard error. The
macro is around 500 lines long and I don't think I should dump it in
here and ask people to fix it for me.
So for now, I will try to go back and somehow change it so that it
doesn't need the number of vars inputted by the user. If I get really
desperate I will come back for more help.
Thanks for taking the time Bruce!
P.S. You might be interested in commenting on my other post that I put
up.

0
felize
11/10/2009 9:57:15 PM
Reply: