Multiple Graphs from Matrix Output

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

Multiple Graphs from Matrix Output

bdates
Hello, all.



I have a matrix based syntax which produces a file of response categories
with which clients endorsed survey items.  I want to use this file to
produce histograms of category use for each item; in some circumstances the
number of items may be near 100.  Matrix file output is always headed as
col1, col2, col3, etc.  I started with the following macro syntax (preceded
by sample data):



data list free / col1 to col4 (4f1).

begin data .

1 2 3 2

3 2 3 2

1 2 2 2

2 3 1 3

3 2 2 2

1 3 3 2

1 2 1 2

2 1 1 1

3 3 3 3

2 1 2 1

1 1 2 2

1 2 3 2

3 2 3 2

1 2 2 2

2 3 1 3

3 2 2 2

1 3 3 2

1 2 1 2

2 1 1 1

3 3 3 3

end data.



define catgraf (!pos !charend('/')) .

!do !var !in ( !1) .

  graph

    /histogram(normal) !var

    /title='Category Distribution' .

!doend .

!enddefine .

catgraf col1 to col4 .



I get graphs for col1 and col4 and the error message:



>Error # 703 in column 26.  Text: to

>The form VARX TO VARY to refer to a range of variables has been used

>incorrectly.

>This command not executed.



I graduated to this syntax (with lots of variations between):



define catgraf (cols=!charend('/')) .

!do !var !in (!cols) .

graph

    /histogram(normal) !var

    /title='Category Distribution' .

!doend .

!enddefine .

catgraf cols=col1 to col4 .



I get graphs for col1 and col4 and the same error message.  If my macro call
line lists the columns, e.g., col1, col2, col3, col4, I get all the graphs.
Most of my macro interations work as long as the columns are listed, but
none do if only the range is provided.  Is there a solution which allows the
use of a range in the macro call rather than needing to list all the
variables, or is it a general function of the graph command?  Thanks in
advance.



Brian



Confidentiality Notice for Email Transmissions: The information in this
message is confidential and may be legally privileged. It is intended solely
for the addressee.  Access to this message by anyone else is unauthorised.
If you are not the intended recipient, any disclosure, copying, or
distribution of the message, or any action or omission taken by you in
reliance on it, is prohibited and may be unlawful.  Please immediately
contact the sender if you have received this message in error. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Multiple Graphs from Matrix Output

peter link
Just to respond quickly, Brian.  Try something like this

In the MACRO definition:
DEFINE catgraf (nmbr1=!TOKENS(1) / nmbr2=!TOKENS(1))

Then your !DO statement would be something like....

!DO !vars=!nmbr1 !TO !nmbr2 .

Finally, in the MACRO call, you would have

nmbr1 = 1 nmbr2 = 14.

You basically define 2 Tokens, 1 for the first variable in your list, and
one for the last variable in your list.  If each variable is in sequence, it
will run from col1 to col14.

This is how I have addressed this problem in the past.

Peter Link
VA San Diego Healthcare System

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of
Dates, Brian
Sent: Friday, June 22, 2007 8:55 AM
To: [hidden email]
Subject: Multiple Graphs from Matrix Output


Hello, all.



I have a matrix based syntax which produces a file of response categories
with which clients endorsed survey items.  I want to use this file to
produce histograms of category use for each item; in some circumstances the
number of items may be near 100.  Matrix file output is always headed as
col1, col2, col3, etc.  I started with the following macro syntax (preceded
by sample data):



data list free / col1 to col4 (4f1).

begin data .

1 2 3 2

3 2 3 2

1 2 2 2

2 3 1 3

3 2 2 2

1 3 3 2

1 2 1 2

2 1 1 1

3 3 3 3

2 1 2 1

1 1 2 2

1 2 3 2

3 2 3 2

1 2 2 2

2 3 1 3

3 2 2 2

1 3 3 2

1 2 1 2

2 1 1 1

3 3 3 3

end data.



define catgraf (!pos !charend('/')) .

!do !var !in ( !1) .

  graph

    /histogram(normal) !var

    /title='Category Distribution' .

!doend .

!enddefine .

catgraf col1 to col4 .



I get graphs for col1 and col4 and the error message:



>Error # 703 in column 26.  Text: to

>The form VARX TO VARY to refer to a range of variables has been used

>incorrectly.

>This command not executed.



I graduated to this syntax (with lots of variations between):



define catgraf (cols=!charend('/')) .

!do !var !in (!cols) .

graph

    /histogram(normal) !var

    /title='Category Distribution' .

!doend .

!enddefine .

catgraf cols=col1 to col4 .



I get graphs for col1 and col4 and the same error message.  If my macro call
line lists the columns, e.g., col1, col2, col3, col4, I get all the graphs.
Most of my macro interations work as long as the columns are listed, but
none do if only the range is provided.  Is there a solution which allows the
use of a range in the macro call rather than needing to list all the
variables, or is it a general function of the graph command?  Thanks in
advance.



Brian



Confidentiality Notice for Email Transmissions: The information in this
message is confidential and may be legally privileged. It is intended solely
for the addressee.  Access to this message by anyone else is unauthorised.
If you are not the intended recipient, any disclosure, copying, or
distribution of the message, or any action or omission taken by you in
reliance on it, is prohibited and may be unlawful.  Please immediately
contact the sender if you have received this message in error. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Multiple Graphs from Matrix Output

peter link
In reply to this post by bdates
Sent that message too quick.....

One more thing, Brian, that I left out - you will need to define a "base"
variable name, as well.  In your case it would be called "col"  So in your
MACRO def add

DEFINE catgraf (nmbr1=!TOKENS(1) / nmbr2=!TOKENS(1) / vname=!TOKENS(1))

Then here, something like this (untested)

 graph

    /histogram(normal) !CONCAT(!vname,!vars))


Then in the MACRO call

catgraf nmbr1 = 1 nmbr2 = 14 vname = col.

Hope this helps

Peter Link
VA San Diego Healthcare System

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of
Dates, Brian
Sent: Friday, June 22, 2007 8:55 AM
To: [hidden email]
Subject: Multiple Graphs from Matrix Output


Hello, all.



I have a matrix based syntax which produces a file of response categories
with which clients endorsed survey items.  I want to use this file to
produce histograms of category use for each item; in some circumstances the
number of items may be near 100.  Matrix file output is always headed as
col1, col2, col3, etc.  I started with the following macro syntax (preceded
by sample data):



data list free / col1 to col4 (4f1).

begin data .

1 2 3 2

3 2 3 2

1 2 2 2

2 3 1 3

3 2 2 2

1 3 3 2

1 2 1 2

2 1 1 1

3 3 3 3

2 1 2 1

1 1 2 2

1 2 3 2

3 2 3 2

1 2 2 2

2 3 1 3

3 2 2 2

1 3 3 2

1 2 1 2

2 1 1 1

3 3 3 3

end data.



define catgraf (!pos !charend('/')) .

!do !var !in ( !1) .

  graph

    /histogram(normal) !var

    /title='Category Distribution' .

!doend .

!enddefine .

catgraf col1 to col4 .



I get graphs for col1 and col4 and the error message:



>Error # 703 in column 26.  Text: to

>The form VARX TO VARY to refer to a range of variables has been used

>incorrectly.

>This command not executed.



I graduated to this syntax (with lots of variations between):



define catgraf (cols=!charend('/')) .

!do !var !in (!cols) .

graph

    /histogram(normal) !var

    /title='Category Distribution' .

!doend .

!enddefine .

catgraf cols=col1 to col4 .



I get graphs for col1 and col4 and the same error message.  If my macro call
line lists the columns, e.g., col1, col2, col3, col4, I get all the graphs.
Most of my macro interations work as long as the columns are listed, but
none do if only the range is provided.  Is there a solution which allows the
use of a range in the macro call rather than needing to list all the
variables, or is it a general function of the graph command?  Thanks in
advance.



Brian



Confidentiality Notice for Email Transmissions: The information in this
message is confidential and may be legally privileged. It is intended solely
for the addressee.  Access to this message by anyone else is unauthorised.
If you are not the intended recipient, any disclosure, copying, or
distribution of the message, or any action or omission taken by you in
reliance on it, is prohibited and may be unlawful.  Please immediately
contact the sender if you have received this message in error. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Multiple Graphs from Matrix Output

bdates
In reply to this post by bdates
Peter,

Just a note to say thanks!  Your amended syntax worked perfectly.  I'm going
to copy it below for others on the list who might be interested.  You may
want to send it to Raynald so he can put it on his site.  It's especially
valuable for those of us who do most of our work in matrix mode and need to
process some of the outfiles produced.

Brian

Macro syntax to loop through contiguous variables for graphing.  vname is
your variable name, e.g., var.  nmbr is the number attached to the variable,
e.g., 01 as in var01.  For the macro call line, nmbr1 is the lowest numbered
variable; nmbr2 is the highest numbered variable.

define catgraf (nmbr1=!tokens(1)/nmbr2=!tokens(1)/vname=!tokens(1))
!do !vars=!nmbr1 !to !nmbr2  .
graph
    /histogram(normal) !concat(!vname,!vars)
    /title='Category Distribution'
    /footnote='col = Item' .
!doend .
!enddefine .
catgraf nmbr1=1 nmbr2=6 vname=col .



Confidentiality Notice for Email Transmissions: The information in this
message is confidential and may be legally privileged. It is intended solely
for the addressee.  Access to this message by anyone else is unauthorised.
If you are not the intended recipient, any disclosure, copying, or
distribution of the message, or any action or omission taken by you in
reliance on it, is prohibited and may be unlawful.  Please immediately
contact the sender if you have received this message in error. Thank you.