Automatically deleting variables that

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Automatically deleting variables that

kemal.suher
Hi to everyone?

I have 1200 cases and 900 variables. These variables are nominal; 0 and 1.
I need to find a way to delete the variables that only contains 0 and
system missing. If I can make it automatically, I can easly make my
analysis. can I make it with a syntax or is there an other way

Thank you very much for all answers in advance

Regards

Kemal Suher

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Automatically deleting variables that

David Marso
Administrator
See FLIP
See COMPUTE (MIN function)
See SELECT IF
In a fine manual near you!
----
kemal.suher wrote
Hi to everyone?

I have 1200 cases and 900 variables. These variables are nominal; 0 and 1.
I need to find a way to delete the variables that only contains 0 and
system missing. If I can make it automatically, I can easly make my
analysis. can I make it with a syntax or is there an other way

Thank you very much for all answers in advance

Regards

Kemal Suher

=====================
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Automatically deleting variables that

Ruben Geert van den Berg
First make sure you have the Python Essentials properly installed. Also, see http://www.spss-tutorials.com/introducing-python-4-installing-and-testing/.

Second, download "spssaux2.py" from https://www.ibm.com/developerworks/community/files/app#/file/108ce263-b14e-4375-9f70-6d1f733d132b. Put this file in the site-packages folder (something like C:\Python27\Lib\site-packages).

Third, run DESCRIPTIVES on your variables. This allows for a quick check later on. Those having std = 0 should be deleted.

Fourth, TEMPORARILY RECODE 0 into SYSMIS like so:

temporary.
recode [variable names here without square brackets] (0 = sysmis).

Fifth, just run

begin program.
import spssaux2
spssaux2.FindEmptyVars(delete = True)
end program.

And you're done.

Use the descriptives from step 3 for a quick inspection. For more on TEMPORARY and RECODE, see http://www.spss-tutorials.com/temporary/ and http://www.spss-tutorials.com/recode/.

Hope that helps.

Ruben
Reply | Threaded
Open this post in threaded view
|

Re: Automatically deleting variables that

Albert-Jan Roskam-2
In reply to this post by kemal.suher
 
This will also work:
 
* sample data.
DATA LIST LIST /var1 var2 var3 var4 var5.
BEGIN DATA
1 1 9 9 0
1 0 0 9 1
END DATA.
RECODE ALL (9=SYSMIS) (ELSE=COPY).
EXECUTE.
 
* actual code.
BEGIN PROGRAM.
import spss, spssaux
with spss.DataStep():
    records = reduce(list.__add__, spss.Dataset().cases[:spss.GetCaseCount()])
vlist = spssaux.GetVariableNamesList()
to_be_deleted = [vname for col, vname in enumerate(vlist) if not any(records[col::len(vlist)])]
if to_be_deleted:
     spss.Submit("delete variables %s." % " ".join(to_be_deleted))
END PROGRAM.
 

Regards,

Albert-Jan




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a

fresh water system, and public health, what have the Romans ever done for us?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




----- Original Message -----

> From: "[hidden email]" <[hidden email]>
> To: [hidden email]
> Cc:
> Sent: Tuesday, July 15, 2014 10:41 PM
> Subject: [SPSSX-L] Automatically deleting variables that
>
> Hi to everyone?
>
> I have 1200 cases and 900 variables. These variables are nominal; 0 and 1.
> I need to find a way to delete the variables that only contains 0 and
> system missing. If I can make it automatically, I can easly make my
> analysis. can I make it with a syntax or is there an other way
>
> Thank you very much for all answers in advance
>
> Regards
>
> Kemal Suher
>
> =====================
> 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
Reply | Threaded
Open this post in threaded view
|

Re: Automatically deleting variables that

David Marso
Administrator
In reply to this post by David Marso
DATA LIST LIST / v1 TO v5.
BEGIN DATA
1 0 1 1 1
0 0 0 0 0
1 0 1 0 1
0 . . . .
END DATA.
FLIP.
COMPUTE @=1.
MATCH FILES / FILE * / KEEP CASE_LBL @ ALL.
COMPUTE @1=1.
COMPUTE TOTAL=SUM(@ TO @1).
SELECT IF TOTAL GT 2.
EXECUTE.
DELETE VARIABLES @ @1 TOTAL.
FLIP.
DELETE VARIABLES CASE_LBL.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Automatically deleting variables that

Bruce Weaver
Administrator

Look Ma--no Python!  ;-)


David Marso wrote
DATA LIST LIST / v1 TO v5.
BEGIN DATA
1 0 1 1 1
0 0 0 0 0
1 0 1 0 1
0 . . . .
END DATA.
FLIP.
COMPUTE @=1.
MATCH FILES / FILE * / KEEP CASE_LBL @ ALL.
COMPUTE @1=1.
COMPUTE TOTAL=SUM(@ TO @1).
SELECT IF TOTAL GT 2.
EXECUTE.
DELETE VARIABLES @ @1 TOTAL.
FLIP.
DELETE VARIABLES CASE_LBL.
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Automatically deleting variables that

Art Kendall
In reply to this post by kemal.suher
What are you planning to do that you want to delete the variables?
Deleting variables is feasible but could very well be inadvisable.



With so many items It appears that these may be items in a summative scale.  Is that so?


Are these true nominal level variables, or are they crude repeated measures of constructs?

Why are some values system missing rather than user missing?  

Most transformations and procedures can handle missing values.

Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Automatically deleting variables that

Andy W
In reply to this post by Bruce Weaver
I agree that Python is the clear choice here - but just wasting my time here are two other no-Python approaches. VARSTOCASES works, but with irregular variable names will add an annoying string to the front. (This example only works out because the set of variables share the shame prefix).

*******************************.
*Varstocases approach.
DATA LIST LIST / v1 TO v5.
BEGIN DATA
1 0 1 1 1
0 0 0 0 0
1 0 1 0 1
0 . . . .
END DATA.

COMPUTE Id = $casenum.
VARSTOCASES /MAKE v FROM v1 TO V5 /INDEX OldVars.
AGGREGATE OUTFILE=* MODE=ADDVARIABLES /BREAK OldVars /Total = SUM(v).
SELECT IF Total > 0.
CASESTOVARS /ID = Id /SEPARATOR = "" /INDEX = OldVars /DROP Total Id.
*******************************.

Matrix will keep the variable names, although is a bit longer code-golf.

*******************************.
*Matrix approach.
DATASET CLOSE ALL.
OUTPUT CLOSE ALL.

DATA LIST LIST / v1 TO v5.
BEGIN DATA
1 0 1 1 1
0 0 0 0 0
1 0 1 0 1
0 . . . .
END DATA.

MATRIX.
GET MyData /FILE = * /VARIABLES = v1 TO v5 /MISSING = 0 /NAME = MyNames.
COMPUTE Keep = (CSUM(MyData) > 0).
COMPUTE Ind = {1:NCOL(MyData)}.
COMPUTE Ind(GRADE(Keep*-1)) = Ind.
COMPUTE Ind = Ind(1:RSUM(Keep)).
COMPUTE Names2 = MyNames(Ind).
SAVE {MyData(1:NROW(MyData),Ind)} /OUTFILE = * /NAMES = Names2.
END MATRIX.
*******************************.

Either won't work for mixed case data - but in case you are one of these people with a version from 10+ years ago... (Also totally agree with Art - it is hard to imagine situations in which you want to do this for statistical analysis or presentation.)
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: Automatically deleting variables that

Albert-Jan Roskam-2
In reply to this post by kemal.suher
FLIP obliterates string variables, which may or may not be a problem for the OP.



------------------------------
On Wed, Jul 16, 2014 5:21 PM CEST Bruce Weaver wrote:

>Look Ma--no Python!  ;-)
>
>
>
>David Marso wrote
>> DATA LIST LIST / v1 TO v5.
>> BEGIN DATA
>> 1 0 1 1 1
>> 0 0 0 0 0
>> 1 0 1 0 1
>> 0 . . . .
>> END DATA.
>> FLIP.
>> COMPUTE @=1.
>> MATCH FILES / FILE * / KEEP CASE_LBL @ ALL.
>> COMPUTE @1=1.
>> COMPUTE TOTAL=SUM(@ TO @1).
>> SELECT IF TOTAL GT 2.
>> EXECUTE.
>> DELETE VARIABLES @ @1 TOTAL.
>> FLIP.
>> DELETE VARIABLES CASE_LBL.
>
>
>
>
>
>-----
>--
>Bruce Weaver
>[hidden email]
>http://sites.google.com/a/lakeheadu.ca/bweaver/
>
>"When all else fails, RTFM."
>
>NOTE: My Hotmail account is not monitored regularly.
>To send me an e-mail, please use the address shown above.
>
>--
>View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Automatically-deleting-variables-that-tp5726722p5726732.html
>Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
>=====================
>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
Reply | Threaded
Open this post in threaded view
|

Re: Automatically deleting variables that

Bruce Weaver
Administrator
Good point, Albert-Jan.  But the OP said, "These variables are nominal; 0 and 1."  So it's (probably) not an issue in this case.  ;-)



Albert-Jan Roskam-2 wrote
FLIP obliterates string variables, which may or may not be a problem for the OP.



------------------------------
On Wed, Jul 16, 2014 5:21 PM CEST Bruce Weaver wrote:

>Look Ma--no Python!  ;-)
>
>
>
>David Marso wrote
>> DATA LIST LIST / v1 TO v5.
>> BEGIN DATA
>> 1 0 1 1 1
>> 0 0 0 0 0
>> 1 0 1 0 1
>> 0 . . . .
>> END DATA.
>> FLIP.
>> COMPUTE @=1.
>> MATCH FILES / FILE * / KEEP CASE_LBL @ ALL.
>> COMPUTE @1=1.
>> COMPUTE TOTAL=SUM(@ TO @1).
>> SELECT IF TOTAL GT 2.
>> EXECUTE.
>> DELETE VARIABLES @ @1 TOTAL.
>> FLIP.
>> DELETE VARIABLES CASE_LBL.
>
>
>
>
>
>-----
>--
>Bruce Weaver
>[hidden email]
>http://sites.google.com/a/lakeheadu.ca/bweaver/
>
>"When all else fails, RTFM."
>
>NOTE: My Hotmail account is not monitored regularly.
>To send me an e-mail, please use the address shown above.
>
>--
>View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Automatically-deleting-variables-that-tp5726722p5726732.html
>Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
>=====================
>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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Automatically deleting variables that

Jon K Peck
There could be other variables in the file that are strings.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        Bruce Weaver <[hidden email]>
To:        [hidden email],
Date:        07/16/2014 04:05 PM
Subject:        Re: [SPSSX-L] Automatically deleting variables that
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Good point, Albert-Jan.  But the OP said, "These variables are nominal; 0 and
1."  So it's (probably) not an issue in this case.  ;-)




Albert-Jan Roskam-2 wrote
> FLIP obliterates string variables, which may or may not be a problem for
> the OP.
>
>
>
> ------------------------------
> On Wed, Jul 16, 2014 5:21 PM CEST Bruce Weaver wrote:
>
>>Look Ma--no Python!  ;-)
>>
>>
>>
>>David Marso wrote
>>> DATA LIST LIST / v1 TO v5.
>>> BEGIN DATA
>>> 1 0 1 1 1
>>> 0 0 0 0 0
>>> 1 0 1 0 1
>>> 0 . . . .
>>> END DATA.
>>> FLIP.
>>> COMPUTE @=1.
>>> MATCH FILES / FILE * / KEEP CASE_LBL @ ALL.
>>> COMPUTE @1=1.
>>> COMPUTE TOTAL=SUM(@ TO @1).
>>> SELECT IF TOTAL GT 2.
>>> EXECUTE.
>>> DELETE VARIABLES @ @1 TOTAL.
>>> FLIP.
>>> DELETE VARIABLES CASE_LBL.
>>
>>
>>
>>
>>
>>-----
>>--
>>Bruce Weaver
>>

> bweaver@

>>
http://sites.google.com/a/lakeheadu.ca/bweaver/
>>
>>"When all else fails, RTFM."
>>
>>NOTE: My Hotmail account is not monitored regularly.
>>To send me an e-mail, please use the address shown above.
>>
>>--
>>View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Automatically-deleting-variables-that-tp5726722p5726732.html
>>Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>>
>>=====================
>>To manage your subscription to SPSSX-L, send a message to
>>

> LISTSERV@.UGA

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

> LISTSERV@.UGA

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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Automatically-deleting-variables-that-tp5726722p5726742.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

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