Date: Fri, 15 May 2009 01:22:33 -0700
Reply-To: Gyorgy Bea <firstname.lastname@example.org>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Gyorgy Bea <email@example.com>
Subject: Re: empty variable
Marta, thank you very much for the syntax. The deleting is working perfect when I try with small number of variables, but I have problems when I run it on a large set of variables (it runs very very slowly) .
I think I need to rewrite my macro, and avoid somehow creating unnecessary variables.
I have a question: why does "compute" always create the new variable, even if it is in a do-if statement, and the if condition is false (so theoretically should not enter inside the loop).
This is the part of my macro that I believe creates my problem:
!DO !cnt=1 !TO !codes
loop #i=1 to #nr.
do if v(#i)=!cnt.
*this is the macro call:
OES vars (q17_1_1 to q17_2_1) varname Q17r codes 417.
The purpose is to create a new variable ONLY when a certain code exists in the given variables (vector v(#i)). So if finds for example code 88, than creates Q17r_88, but shouldn't create Q17r_100, Q17r_101, Q17r_102 etc... if codes 100, 101, 102 don't exists in my list (!vars).
I would happily provide more details about my syntax if needed.
Thank you very much,
From: Marta García-Granero <firstname.lastname@example.org>
Sent: Thursday, May 14, 2009 7:14:24 PM
Subject: Re: empty variable
Gyorgy Bea wrote:
> Thank you Marta, and Art for your answers. I realize that I wasn't
> very specific with my question. I want to detect the empty variables,
> and delete them. My problem started from a macro which creates too
> many variables, that I don't need. So I guess it's a bit far fetched
> solution deleting them, but I just couldn't think about any other for
> the moment.
Now that my Gmail account is working again, I post the solution I sent
to Gyorgy from an alternate e-mail address:
This is the solution (fully automatic, no need to give variable names,
it uses the word ALL to indicate every variable in the dataset).
* Make a working copy of the dataset (to leave the original untouched) *.
DATASET COPY CleanedData.
* Make a list of all variables, with their N *.
DATASET DECLARE VarListWithN.
/IF COMMANDS = "Descriptives"
SUBTYPES = "Descriptive Statistics"
/DESTINATION FORMAT = SAV
OUTFILE = VarListWithN.
SET TVars Names.
* Replace ALL by a list of variables if you don't want to clean the
whole dataset *.
DATASET ACTIVATE VarListWithN.
* Go to the list an keep only those variables with N=0 (to eliminate
* It can be easily modified to delete variables with low sample size,
* like, for instance, N<10: use (N LT 10) instead of (N EQ 0) *.
SELECT IF (Var1 NE 'Valid N (listwise)') AND (N EQ 0).
* Print the list of variable names to be deleted, with their N *.
LIST VARIABLES=Var1 N.
* Write a syntax file with DELETE VARIABLES commands *.
WRITE OUTFILE 'C:\Temp\IncludeSyntax.sps' /'DELETE VARIABLES ' Var1 '.'.
* Go to copy of dataset and run the syntax file to delete all unwanted
DATASET ACTIVATE CleanedData.
DATASET CLOSE VarListWithN.
For miscellaneous SPSS related statistical stuff, visit:
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
For a list of commands to manage subscriptions, send the command