SPSS Macros: Include macro var in title?

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

SPSS Macros: Include macro var in title?

Seumas Rogan
Hi -
 
I've borrowed from Raynald's very helpful pages, but now I'm stumped!
 
I want to create a series of several hundred tables; I want to include the name of the tabulated variable for each table in the title of the table... I've tried several combinations of !QUOTE, !UNQUOTE and !CONCAT, but I haven't been able to get the result I want. I have row variables VAR001 to VAR999.
 
Here is a macro for the first five tables. I just don't know how to include the row variable in the title. Thanks for any thelp!
 
JR
 
DEFINE !XTABLE(row=!CHAREND('|') /col=!CMDEND)
!DO !l !IN (!row).
CTABLES  
 /VLABELS VARIABLES= !I !col DISPLAY=DEFAULT 
 /TABLE !I [COLPCT.COUNT PCT40.1]  BY !col
 /SLABELS VISIBLE=NO
/CATEGORIES VARIABLES= !I  ORDER=A KEY=VALUE EMPTY=INCLUDE
 /CATEGORIES VARIABLES=!col ORDER=A KEY=VALUE EMPTY=INCLUDE
  /TITLES
TITLE=!QUOTE(!CONCAT(!l, "by VAR999")).
    !DOEND.
!ENDDEFINE.
SET MPRINT=NO.
!XTABLE row= VAR001 VAR002 VAR003 VAR004 VAR005 |COL=VAR999.
Reply | Threaded
Open this post in threaded view
|

Re: SPSS Macros: Include macro var in title?

David Marso
Administrator
On Sun, 3 Oct 2010 13:50:05 -0700, Seumas Rogan <[hidden email]> wrote:

>Hi -

I've borrowed from Raynald's very helpful pages, but now I'm stumped!

I want to create a series of several hundred tables;�I�want�to include the name
of the tabulated variable for each table in the title of the table... I've
tried�several combinations of !QUOTE, !UNQUOTE and !CONCAT, but I haven't been
able to get the result I want. I have row variables VAR001 to VAR999.

Here is�a macro for the first five tables. I just don't know how to�include the
row variable in the title. Thanks for any thelp!

JR

DEFINE !XTABLE(row=!CHAREND('|') /col=!CMDEND)
!DO !l !IN (!row).
CTABLES��
�/VLABELS VARIABLES= !I !col DISPLAY=DEFAULT�
�/TABLE !I [COLPCT.COUNT PCT40.1]� BY !col
�/SLABELS VISIBLE=NO
/CATEGORIES VARIABLES= !I� ORDER=A KEY=VALUE EMPTY=INCLUDE
�/CATEGORIES VARIABLES=!col ORDER=A KEY=VALUE EMPTY=INCLUDE
� /TITLES
TITLE=!QUOTE(!CONCAT(!l, "by VAR999")).
��� !DOEND.
!ENDDEFINE.
SET MPRINT=NO.
!XTABLE row= VAR001 VAR002 VAR003 VAR004 VAR005 |COL=VAR999.


DEFINE !XTABLE(row=!CHAREND('|') /col=!CMDEND)
!DO !I !IN (!row)
CTABLES
 /VLABELS VARIABLES= !I !col DISPLAY=DEFAULT
 /TABLE !I[C] [COLPCT.COUNT PCT40.1] BY !col[C]
 /SLABELS VISIBLE=NO
 /CATEGORIES VARIABLES= !I !col ORDER=A KEY=VALUE EMPTY=INCLUDE
 /TITLES
 TITLE=!QUOTE(!CONCAT(!I, " by VAR999")).
!DOEND.
!ENDDEFINE.

<RANT>
HINTS!!!!!!
"I've borrowed from Raynald's very helpful pages..." ROFLMFAO!!!  Seems very
symmetrical since he has "borrowed" from everybody else!!!  Too bad I can't
afford the time to do a research project to trace back all of his
misattributed gems ;-)
1.  Before converting a syntax program snippet to a macro VERIFY that the damned
code works as stand alone.  Note the crucial [C] after the TABLE subcommand...
Note also that you have lower case !l in your !DO loop and !I as your
working values...
2.  Don't write SPSS code when you are drunk or stoned.
I can get away with it but most people cant!!!
3.  There are a bunch of gremlins ( � )showing up in your posted code.  This
might be a browser issue or an editor issue?
</RANT>
BTW:  Take it as you wish... This solves your issue, but rule out extraneous
issues before decorating things with TITLES etc...  Also helps to post your
error messages etc...The one I received was about crossing two scale
variables ;-).  Anyway, hope this helps.
David

=====================
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

replicate records

Tibor Toth
Hello to everyone,

I have a sav file with about 400 records and 5 variables.  The last variable (V5 below) is a weight variable.  I need to replicate each record the number of times indicated in the V5 variable.  Any suggestions on how to do this?

EXAMPLE

Original
ID      V2      V3      V4      V5
1       east    0.5     1       2
2       west    1       2       3

After transformation
ID      V2      V3      V4      V5
1       east    0.5     1       2
1       east    0.5     1       2
2       west    1       2       3
2       west    1       2       3
2       west    1       2       3

Thanks in advance,

Tibor


Tibor Tóth, Ph.D.

Center for Applied Demography & Survey Research
University of Delaware
292 Graham Hall
Newark, DE 19716
phone: (302)831-3320
e-mail: [hidden email]

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: replicate records

Bruce Weaver
Administrator
Tibor Toth wrote
Hello to everyone,

I have a sav file with about 400 records and 5 variables.  The last variable (V5 below) is a weight variable.  I need to replicate each record the number of times indicated in the V5 variable.  Any suggestions on how to do this?

EXAMPLE

Original
ID      V2      V3      V4      V5
1       east    0.5     1       2
2       west    1       2       3

After transformation
ID      V2      V3      V4      V5
1       east    0.5     1       2
1       east    0.5     1       2
2       west    1       2       3
2       west    1       2       3
2       west    1       2       3

Thanks in advance,

Tibor
loop #i = 1 to v5.
- xsave outfile = "C:\temp\expanded.sav" .
end loop.

get file = "C:\temp\expanded.sav" .

--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: replicate records

Art Kendall
Bruce's method will work if you want to produce a file for another package.

If you just need to replicate in analysis rather than producing another file use WEIGHT.
WEIGHT BY V5.
...
to turn off weighting
WEIGHT OFF.

Art Kendall
Social Research Consultants

On 10/4/2010 9:09 AM, Bruce Weaver wrote:
Tibor Toth wrote:
Hello to everyone,

I have a sav file with about 400 records and 5 variables.  The last
variable (V5 below) is a weight variable.  I need to replicate each record
the number of times indicated in the V5 variable.  Any suggestions on how
to do this?

EXAMPLE

Original
ID      V2      V3      V4      V5
1       east    0.5     1       2
2       west    1       2       3

After transformation
ID      V2      V3      V4      V5
1       east    0.5     1       2
1       east    0.5     1       2
2       west    1       2       3
2       west    1       2       3
2       west    1       2       3

Thanks in advance,

Tibor


loop #i = 1 to v5.
- xsave outfile = "C:\temp\expanded.sav" .
end loop.

get file = "C:\temp\expanded.sav" .



-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/SPSS-Macros-Include-macro-var-in-title-tp3112564p3173340.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

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

===================== 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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: replicate records

Tibor Toth

Bruce, Art,

 

Thank you for your responses.

 

My intention is to create an extract for a different package that can’t easily deal with weights.  Bruce, your code works well.

 

Thank you for the solution!

 

Tibor

 

 

Tibor Tóth, Ph.D.

 

Center for Applied Demography & Survey Research

University of Delaware

292 Graham Hall

Newark, DE 19716

phone: (302)831-3320

e-mail: [hidden email]

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Art Kendall
Sent: Monday, October 04, 2010 9:40 AM
To: [hidden email]
Subject: Re: replicate records

 

Bruce's method will work if you want to produce a file for another package.

If you just need to replicate in analysis rather than producing another file use WEIGHT.
WEIGHT BY V5.
...
to turn off weighting
WEIGHT OFF.

Art Kendall
Social Research Consultants

On 10/4/2010 9:09 AM, Bruce Weaver wrote:

Tibor Toth wrote:
 
Hello to everyone,
 
I have a sav file with about 400 records and 5 variables.  The last
variable (V5 below) is a weight variable.  I need to replicate each record
the number of times indicated in the V5 variable.  Any suggestions on how
to do this?
 
EXAMPLE
 
Original
ID      V2      V3      V4      V5
1       east    0.5     1       2
2       west    1       2       3
 
After transformation
ID      V2      V3      V4      V5
1       east    0.5     1       2
1       east    0.5     1       2
2       west    1       2       3
2       west    1       2       3
2       west    1       2       3
 
Thanks in advance,
 
Tibor
 
 
 
loop #i = 1 to v5.
- xsave outfile = "C:\temp\expanded.sav" .
end loop.
 
get file = "C:\temp\expanded.sav" .
 
 
 
-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/
 
"When all else fails, RTFM."
 
NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
 
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/SPSS-Macros-Include-macro-var-in-title-tp3112564p3173340.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.
 
=====================
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
 

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