Date: Fri, 15 May 2009 01:22:33 -0700
Reply-To: Gyorgy Bea <ciao_beatag@yahoo.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Gyorgy Bea <ciao_beatag@yahoo.com>
Subject: Re: empty variable
In-Reply-To: <4A0C4360.3030103@gmail.com>
Content-Type: multipart/alternative;
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:
vector v=!vars.
!DO !cnt=1 !TO !codes
loop #i=1 to #nr.
do if v(#i)=!cnt.
compute !concat(!varname,"_",!cnt)=1.
end if.
end loop.
!DOEND
*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,
Beata
________________________________
From: Marta García-Granero <mgarciagranero@gmail.com>
To: SPSSX-L@LISTSERV.UGA.EDU
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.
OMS
/SELECT TABLES
/IF COMMANDS = "Descriptives"
SUBTYPES = "Descriptive Statistics"
/DESTINATION FORMAT = SAV
OUTFILE = VarListWithN.
PRESERVE.
SET OLANG=ENGLISH.
SET TVars Names.
* Replace ALL by a list of variables if you don't want to clean the
whole dataset *.
DESCRIPTIVES
VARIABLES=ALL
/STATISTICS=MIN MAX
/SORT=NAME.
OMSEND.
DATASET ACTIVATE VarListWithN.
* Go to the list an keep only those variables with N=0 (to eliminate
them later)
* 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 '.'.
EXE.
* Go to copy of dataset and run the syntax file to delete all unwanted
variables *.
DATASET ACTIVATE CleanedData.
DATASET CLOSE VarListWithN.
INCLUDE 'C:\Temp\IncludeSyntax.sps'.
RESTORE.
Regards,
Marta
--
For miscellaneous SPSS related statistical stuff, visit:
http://gjyp.nl/marta/
=====================
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
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
[text/html]
|