LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (November 2003)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 12 Nov 2003 12:01:28 -0200
Reply-To:     Marcos Sanches <marcos_sanches@gallup.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Marcos Sanches <marcos_sanches@gallup.com>
Subject:      Re: macro
In-Reply-To:  <442531134F379D43AB31B66530CC4BEB967943@cheney.lodgenet.com>
Content-Type: text/plain; charset="iso-8859-1"

Thanks very much Jim!

Your first suggestion is just what I want, and in fact will work for some cases, but my variables names are not always like those, they can be very different sometimes. In this case the !CONCAT wouldn't work. A natural extension of my macro would be something like

DEFINE !DoIt (var1=!CMDEND ; var2 = !CMDEND)

Is this possible? How do I call the macro in this case? What to do inside the macro so that SPSS correlate the element 'i' of var1 with the element i (and only it) of var2? It would be something much like this:

DEFINE !DoIt (var1=!CMDEND var2 = !CMDEND) !DO !i !IN (!var1). compute #a = #a+1. !DO !J !IN (!var2). compute #b=#b+1. !IF (#a !EQ #b) !THEN CORRELATIONS /VARIABLES=!i var_x /PRINT=TWOTAIL NOSIG /MISSING=PAIRWISE . !IFEND !DOEND !DOEND. !ENDDEFINE.

The problema is that it gives me a error message because of the second !CMDEND. Also, I don't know if the 'compute' and the variables #a and #b will be acepted...

TIA

Marcos

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of Marks, Jim Sent: Tuesday, November 11, 2003 8:42 PM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: macro

Marcos:

You can nest "!DO" commands within a macro-- make sure you have the appropriate number of "!DOEND" statements.

For your example, you don't need a second !DO, however. The pairs of variables share a common root and number-- they differ on "a" and "b" at the end of the variable name.

You can use "!CONCAT" to construct variables names with a var#a var#b pattern. This will give you bivariate correlations var1a with var1b up to var#a with var#b (I tested with 4 paired variables).

** sample data for testing. DATA LIST FREE /id var1a var1b var2a var2b var3a var3b var4a var4b. BEGIN DATA 1 .5 .5 .4 .6 2 3 55 57 2 .3 .4 .5 .6 4 7 45 44 3 .5 .45 .5 .55 7 9 35 20 4 .33 .3 .4 .8 2 1 20 11 5 .7 .79 .3 .5 3 5 66 54 END DATA.

** numeric looping macro. DEFINE !DoItnb (). !DO !i = 1 !TO 4

CORRELATIONS /VARIABLES=!CONCAT(var,!i,a) !CONCAT(var,!i,b) /PRINT=TWOTAIL NOSIG /MISSING=PAIRWISE . !DOEND. !ENDDEFINE.

!DOItnb.

If you want to correlate var1a with var2b that will require a different macro. This will create bivariate correlations

var1a with var1b --> var1a with var4b var2a with var2b --> var2a with var4b etc.

DEFINE !DoItge ().

!DO !i = 1 !TO 4 !DO !j = 1 !TO 4 !IF (!j !GE !i) !THEN CORRELATIONS /VARIABLES=!CONCAT(var,!i,a) !CONCAT(var,!j,b) /PRINT=TWOTAIL NOSIG /MISSING=PAIRWISE . !IFEND !DOEND !DOEND. !ENDDEFINE.

!DoItge.

This will generate thousands of correlations in a 500 variable set-- use it with caution :)

Jim Marks Senior Market Analyst LodgeNet Entertainment Corporation

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of Marcos Sanches Sent: Tuesday, November 11, 2003 10:48 AM To: SPSSX-L@LISTSERV.UGA.EDU Subject: macro

Hi listers!

Supose the following macro:

DEFINE !DoIt (var=!CMDEND) !DO !i !IN (!var). CORRELATIONS /VARIABLES=!i var_x /PRINT=TWOTAIL NOSIG /MISSING=PAIRWISE . !DOEND. !ENDDEFINE.

Now, if I write

!DoIt var = var1 var2 var3 var4 var5 var6.

Then I'll get the Correlation procedure of all these variables with var_x. Supose now I have to get correlations between a lot of variables pairs. Like this:

var1a with var1b var2a with var2b var3a with var3b ... var500a with var500b

All I want is a macro almost like the above, but I need to enter with two vectors of variables, not just one. var_x in the above macro must be anoter macro variable, like !j.

How do I acomplish that?

TIA

Marcos


Back to: Top of message | Previous page | Main SPSSX-L page