|
Hi All, Is there any possibility to check weather a variable is empty through all cases? I want to detect those variables, that are totally empty, have no cases. Thanks a lot, Beata |
|
If your variable is numeric, an old-fashioned way is to use
FREQUENCIES and use the subcommand to suppress the frequency tables
and statistics.
IIRC there is some python way to do this also. Open a new instance of SPSS. Copy the syntax below to a syntax file. Click <run>. Click <all>. Is this what you are looking for? data list list/id (f2) v1(f2) v2(f2) v3(a1) v4(a1). begin data 01 1 1 a a 02 2 1 b a 03 1 1 ' ' ' ' 04 2 1 b a end data. missing values v1 v2 (1) v3 v4 (' ', 'a'). frequencies vars = v1 to v4 /format = notable /statistics = none. Art Kendall Social Research Consultants Gyorgy Bea wrote: ===================== 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 |
|
In reply to this post by Gyorgy Bea
Gyorgy Bea wrote:
> Is there any possibility to check wether a variable is empty through > all cases? I want to detect those variables, that are totally empty, > have no cases. > What do you plan to do later with those variables? If you just want to know if there are empty variables, use a simple procedure like DESCRIPTIVES. The empty variables will have N=0. If you want to locate them to get rid of them, then you will need something more complex, like a macro. Locating them is easy: TEMPORARY. SET TVars Names. DESCRIPTIVES VARIABLES=ALL /STATISTICS=MIN MAX /SORT=NAME. You will get a list of every variable in your dataset, sorted by name, with their valid N. This is a good starting point for a macro that uses OMS to capture the list, select those variables with n=0 and then drop them from the dataset. Ask the list for help if you want to go that way and don't know how. HTH, Marta García-Granero -- For miscellaneous SPSS related statistical stuff, visit: http://gjyp.nl/marta/ ===================== 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 |
|
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. From: Marta García-Granero <[hidden email]> To: [hidden email] Sent: Thursday, May 14, 2009 5:49:31 PM Subject: Re: empty variable Gyorgy Bea wrote: > Is there any possibility to check wether a variable is empty through > all cases? I want to detect those variables, that are totally empty, > have no cases. > What do you plan to do later with those variables? If you just want to know if there are empty variables, use a simple procedure like DESCRIPTIVES. The empty variables will have N=0. If you want to locate them to get rid of them, then you will need something more complex, like a macro. Locating them is easy: TEMPORARY. SET TVars Names. DESCRIPTIVES VARIABLES=ALL /STATISTICS=MIN MAX /SORT=NAME. You will get a list of every variable in your dataset, sorted by name, with their valid N. This is a good starting point for a macro that uses OMS to capture the list, select those variables with n=0 and then drop them from the dataset. Ask the list for help if you want to go that way and don't know how. HTH, Marta García-Granero -- For miscellaneous SPSS related statistical stuff, visit: http://gjyp.nl/marta/ ===================== 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 |
|
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 [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 |
|
In reply to this post by Gyorgy Bea
There is a Python function on the spssaux2 module available from SPSS Developer that will find empty (or all blank for strings) with the option of deleting them.
I'm away from my computer, but it has an obvious name. HTH, Jon Peck From: SPSSX(r) Discussion <[hidden email]> To: [hidden email] <[hidden email]> Sent: Thu May 14 11:10:05 2009 Subject: Re: [SPSSX-L] empty variable 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. From: Marta García-Granero <[hidden email]> To: [hidden email] Sent: Thursday, May 14, 2009 5:49:31 PM Subject: Re: empty variable Gyorgy Bea wrote: > Is there any possibility to check wether a variable is empty through > all cases? I want to detect those variables, that are totally empty, > have no cases. > What do you plan to do later with those variables? If you just want to know if there are empty variables, use a simple procedure like DESCRIPTIVES. The empty variables will have N=0. If you want to locate them to get rid of them, then you will need something more complex, like a macro. Locating them is easy: TEMPORARY. SET TVars Names. DESCRIPTIVES VARIABLES=ALL /STATISTICS=MIN MAX /SORT=NAME. You will get a list of every variable in your dataset, sorted by name, with their valid N. This is a good starting point for a macro that uses OMS to capture the list, select those variables with n=0 and then drop them from the dataset. Ask the list for help if you want to go that way and don't know how. HTH, Marta García-Granero -- For miscellaneous SPSS related statistical stuff, visit: http://gjyp.nl/marta/ ===================== 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 |
|
In reply to this post by Marta Garcia-Granero
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 <[hidden email]> To: [hidden email] 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 [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 |
|
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 > 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 <[hidden email]> > *To:* [hidden email] > *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 > [hidden email] <mailto:[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 > -- For miscellaneous SPSS related statistical stuff, visit: http://gjyp.nl/marta/ ===================== 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 |
|
In reply to this post by Marta Garcia-Granero
Dear all,
1) I've been trying to make a .sav file with frequencies with the OMS (more or less like the syntax Marta wrote for Gyorgy to delete empty variables). However, it's not working and I'm not getting any error messages either. Could anyone please tell me what I'm doing wrong here? 2) Is it correct that I can include syntax containing OMS commands only with INSERT instead of INCLUDE? The other day, this seemed to be the case although I don't quite understand why. ***Create fake data SET SEED=123456. NEW FIL. INP PRO. LOOP #I=1 to 30. COMP ID=#I. COMP throwdice=RND(RV.UNI(.5,6.5)). END CAS. END LOOP. END FIL. END INP PRO. EXE. ***End create fake data ***OMS DATAS DEC Freq. OMS /SEL TAB /IF COM=['Frequencies'] sub=['throwdice'] /DES FOR=SAV OUTFILE=Freq VIE=NO. FRE throwdice. OMSEND. DATAS ACT Freq. See all the ways you can stay connected to friends and family |
|
Ruben van den Berg wrote:
> > 1) I've been trying to make a .sav file with frequencies with the OMS > (more or less like the syntax Marta wrote for Gyorgy to delete empty > variables). However, it's not working and I'm not getting any error > messages either. Could anyone please tell me what I'm doing wrong here? > > 2) Is it correct that I can include syntax containing OMS commands > only with INSERT instead of INCLUDE? The other day, this seemed to be > the case although I don't quite understand why. The subcommand in OMS is wrong. Try this (tested) OMS /SEL TAB /IF COM=['Frequencies'] sub=['Frequencies'] /DES FOR=SAV OUTFILE=Freq VIE=NO. The name of the table is not the same as the OMS identifier. The FREQUENCIES command has 2 subtypes: 'Frequencies' and 'Descriptives' (well, and other different for the graphs, in case you select one). I always use UTILITIES -> OMS CONTROL PANEL to build OMS code. It saves me a lot of pain. HTH, Marta > > ***Create fake data > > SET SEED=123456. > NEW FIL. > INP PRO. > LOOP #I=1 to 30. > COMP ID=#I. > COMP throwdice=RND(RV.UNI(.5,6.5)). > END CAS. > END LOOP. > END FIL. > END INP PRO. > EXE. > > ***End create fake data > > ***OMS > > DATAS DEC Freq. > OMS > /SEL TAB > /IF COM=['Frequencies'] sub=['throwdice'] > /DES FOR=SAV > OUTFILE=Freq > VIE=NO. > > FRE throwdice. > > OMSEND. > > DATAS ACT Freq. -- For miscellaneous SPSS related statistical stuff, visit: http://gjyp.nl/marta/ ===================== 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 |
|
In reply to this post by Marta Garcia-Granero
Ok, I'm back from Directions.
Here is a program that deletes all empty numeric and string variables. begin program. import spss, spssaux2 spssaux2.FindEmptyVars(delete=True) end program. It needs the Python programmability plugin and the spssaux2.py module from Developer Central. Regards, Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Marta García-Granero Sent: Friday, May 15, 2009 10:55 AM To: [hidden email] Subject: Re: [SPSSX-L] empty variable 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 > 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 <[hidden email]> > *To:* [hidden email] > *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 > [hidden email] <mailto:[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 > -- For miscellaneous SPSS related statistical stuff, visit: http://gjyp.nl/marta/ ===================== 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 |
|
In reply to this post by Ruben Geert van den Berg
The problem is
your OMS command is not capturing any output, because the subtype does not
match the table that Frequencies generates. The subtype can be found from
Utilities>OMS Identifiers or by right clicking in the outline on an instance
of such a table and choosing Copy OMS Table Subtype. In this case, the correct
subtype is 'Frequencies' HTH, Jon Peck From: SPSSX(r)
Discussion [mailto:[hidden email]] On
Behalf Of Ruben van den Berg Dear all, See all the ways you can stay connected to
friends and family |
|
In reply to this post by Gyorgy Bea
Shalom
If I understand you data correctly you my consider a deferent way . Instaed of a macro you can restractur your file to get the same result . Here is a syntex example . title 'avoid empty variables ' . dataset close all. DATA LIST / id var1 to var4 (F1, 1x , 4f3) . BEGIN DATA 1 3 1 6 2 10 11 3 3 8 3 3 5 4 3 5 5 8 5 4 4 4 6 5 5 5 5 7 1 4 6 8 11 12 8 END DATA. SORT CASES BY id . dataset name orig . dataset copy long . dataset ACTIVATE long . VARSTOCASES /MAKE var FROM var1 to var4 /INDEX = seq(4) /KEEP = ID /NULL = KEEP. AGGREGATE /OUTFILE=* /BREAK=id var /N=N. select if var gt 0 . SORT CASES BY id var . CASESTOVARS /ID = id /INDEX = var /GROUPBY = VARIABLE . match file file= orig / file=* / by id . execute . Hillel vardi BGU Gyorgy Bea wrote: > 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 <[hidden email]> > *To:* [hidden email] > *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 > [hidden email] <mailto:[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 |
|
In reply to this post by Ruben Geert van den Berg
At 06:08 AM 5/15/2009, Ruben van den Berg wrote:
1) I've been trying to make a .sav file with frequencies with the OMS (more or less like the syntax Marta wrote for Gyorgy to delete empty variables). AGGREGATE may be more direct; see below, with your test data. If you also want the percents, it's a little more complicated: you need a second AGGREGATE with MODE=ADDVARIABLES, to put the total of all the frequencies in each record. AGGREGATE OUTFILE=* /BREAK = throwdice /Frequency = NU. LIST. List |-----------------------------|---------------------------| |Output Created |15-MAY-2009 13:52:37 | |-----------------------------|---------------------------| throwdice Frequency 1.00 4 2.00 2 3.00 3 4.00 8 5.00 8 6.00 5 Number of cases read: 6 Number of cases listed: 6 ===================== 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 |
|
In reply to this post by Peck, Jon
Thank you, Jon for the tip. It works perfectly! Best regards, Beata From: "Peck, Jon" <[hidden email]> To: [hidden email] Sent: Friday, May 15, 2009 5:20:48 PM Subject: Re: empty variable Ok, I'm back from Directions. Here is a program that deletes all empty numeric and string variables. begin program. import spss, spssaux2 spssaux2.FindEmptyVars(delete=True) end program. It needs the Python programmability plugin and the spssaux2.py module from Developer Central. Regards, Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Marta García-Granero Sent: Friday, May 15, 2009 10:55 AM To: [hidden email] Subject: Re: [SPSSX-L] empty variable 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 > 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 <[hidden email]> > *To:* [hidden email] > *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: > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] <mailto:[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 > -- For miscellaneous SPSS related statistical stuff, visit: http://gjyp.nl/marta/ ===================== 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 |
| Free forum by Nabble | Edit this page |
