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 (May 2009)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 15 May 2009 10:55:00 +0200
Reply-To:     Marta García-Granero <mgarciagranero@gmail.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Marta García-Granero <mgarciagranero@gmail.com>
Subject:      Re: empty variable
In-Reply-To:  <48530.29244.qm@web46016.mail.sp1.yahoo.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Gyorgy Bea escribió: > 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 > The variable will always created, I'm afraid. Your loop tests the condition for every case. If the condition is true for a given case, then (for that case), the value is set to 1, otherwise it is left as missing, but the variable is computed first (with all values set to missing), and then, individual values are set to 1 if the DO IF condition is true.

I am absolutely sure that there is a Python solution for that (no sarcasm intended, Jon), but I'm still out of that game, so I'll step back and let others (with expertise on Python) take the challenge.

Regards, Marta > > > *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 <mailto: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 >

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


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