I want to strip out the variable labels, value labels and missing values from all the variables in an SPSS data set. The following excerpt from the SPSS viewer uses FREQUENCIES to confirm that the variable labels have not been removed from three variables. Could someone please tell me what I'm doing wrong? Thanks.
string v (A10). VECTOR V=id to surveyc. LOOP #I=1 TO 3. VAR LABELS V(#I) ' '. END LOOP. FREQUENCIES VARIABLES=id to surveyc. Frequencies C:\DATA\SPSS\ckcs220\sdatac19.sav Statistics id Student ID location Project Location surveyc Survey Category N Valid 828 828 828 Missing 0 0 0 |
Hi Spruce!
First, are you sure that you really want to remove these labels? IMHO, this is very rarely a good idea. If you don't want to see them in your ouput, you could try set tva names tnu values. To the best of my knowledge, you can't edit dictionary information (information about your data like all sorts of labels) in a VECTOR or DO REPEAT since these only support transformation commands. Stripping the value labels and missing values for a number of variables is easy if they are adjacent in your dataset. You can use 'TO' here. Variable labels are a bit harder since "Multiple variables can be assigned labels on a single VARIABLE LABELS command. Only one label can be assigned to each variable, and each label can apply to only one variable." If the number of variables is small, just strip them 'by hand' (like the example below). If the number is large and the variable names are systematic (like v1, v2, v3), a macro could come in handy. If the number is large and the names are not systematic (Tinky, Lala...) then a small Python script is your best option. Or you could build basic syntax with copying-pasting variable names into EXCEL (create one line of syntax for each command in which only the variable name changes). Best, Ruben P.s. for a tiny example of just basic syntax (I think this is the shortest possible without abbreviations), try: *Create test data. data list free/tinky lala po dipsy. begin data 0 0 0 0 1 1 1 1 2 2 2 2 end data. *Apply three types of dictionary info. variable labels tinky'Hello!'Lala'The',po'Sun is',dipsy'shining'. value labels tinky to dipsy 0'Missing'1'Happy'2'Toddlers'. missing values tinky to dipsy(0). *Strip all dictionary info. Mind you that in the 'variable labels' command, I need to include all variable names which may become tedious if the number of variables is large. value labels tinky to dipsy. missing values tinky to dipsy(). variable labels tinky''lala''po''dipsy''. > Date: Tue, 1 Mar 2011 17:58:56 -0800 > From: [hidden email] > Subject: Stripping off attributes: Variable labels in a vector loop > To: [hidden email] > > I want to strip out the variable labels, value labels and missing values from > all the variables in an SPSS data set. The following excerpt from the SPSS > viewer uses FREQUENCIES to confirm that the variable labels have not been > removed from three variables. Could someone please tell me what I'm doing > wrong? Thanks. > > string v (A10). > VECTOR V=id to surveyc. > LOOP #I=1 TO 3. > VAR LABELS V(#I) ' '. > END LOOP. > > FREQUENCIES > VARIABLES=id to surveyc. > > Frequencies > C:\DATA\SPSS\ckcs220\sdatac19.sav > > Statistics > id Student ID location Project Location surveyc Survey Category > N Valid 828 828 828 > Missing 0 0 0 > > > > -- > View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Stripping-off-attributes-Variable-labels-in-a-vector-loop-tp3405980p3405980.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 |
Suppressing value labels with the SET command
is good advice. Missing values, however, cannot be treated as valid through
a SET command -- but many commands, including Frequencies, have the ability
to treat user-missing values as valid:
frequencies variables=varlist /missing=include. From: Ruben van den Berg <[hidden email]> To: [hidden email] Date: 03/02/2011 04:22 AM Subject: Re: Stripping off attributes: Variable labels in a vector loop Sent by: "SPSSX(r) Discussion" <[hidden email]> Hi Spruce! First, are you sure that you really want to remove these labels? IMHO, this is very rarely a good idea. If you don't want to see them in your ouput, you could try set tva names tnu values. To the best of my knowledge, you can't edit dictionary information (information about your data like all sorts of labels) in a VECTOR or DO REPEAT since these only support transformation commands. Stripping the value labels and missing values for a number of variables is easy if they are adjacent in your dataset. You can use 'TO' here. Variable labels are a bit harder since "Multiple variables can be assigned labels on a single VARIABLE LABELS command. Only one label can be assigned to each variable, and each label can apply to only one variable." If the number of variables is small, just strip them 'by hand' (like the example below). If the number is large and the variable names are systematic (like v1, v2, v3), a macro could come in handy. If the number is large and the names are not systematic (Tinky, Lala...) then a small Python script is your best option. Or you could build basic syntax with copying-pasting variable names into EXCEL (create one line of syntax for each command in which only the variable name changes). Best, Ruben P.s. for a tiny example of just basic syntax (I think this is the shortest possible without abbreviations), try: *Create test data. data list free/tinky lala po dipsy. begin data 0 0 0 0 1 1 1 1 2 2 2 2 end data. *Apply three types of dictionary info. variable labels tinky'Hello!'Lala'The',po'Sun is',dipsy'shining'. value labels tinky to dipsy 0'Missing'1'Happy'2'Toddlers'. missing values tinky to dipsy(0). *Strip all dictionary info. Mind you that in the 'variable labels' command, I need to include all variable names which may become tedious if the number of variables is large. value labels tinky to dipsy. missing values tinky to dipsy(). variable labels tinky''lala''po''dipsy''. > Date: Tue, 1 Mar 2011 17:58:56 -0800 > From: [hidden email] > Subject: Stripping off attributes: Variable labels in a vector loop > To: [hidden email] > > I want to strip out the variable labels, value labels and missing values from > all the variables in an SPSS data set. The following excerpt from the SPSS > viewer uses FREQUENCIES to confirm that the variable labels have not been > removed from three variables. Could someone please tell me what I'm doing > wrong? Thanks. > > string v (A10). > VECTOR V=id to surveyc. > LOOP #I=1 TO 3. > VAR LABELS V(#I) ' '. > END LOOP. > > FREQUENCIES > VARIABLES=id to surveyc. > > Frequencies > C:\DATA\SPSS\ckcs220\sdatac19.sav > > Statistics > id Student ID location Project Location surveyc Survey Category > N Valid 828 828 828 > Missing 0 0 0 > > > > -- > View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Stripping-off-attributes-Variable-labels-in-a-vector-loop-tp3405980p3405980.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 |
In reply to this post by spruce18b
I know that removing the attributes of variables removes meaning from the data. My objective is to present my students with a naked file and to ask them to add the variable labels, value labels, missing values and other attributes so that they will understand what is required to make a data file understandable.
It took only a couple of minutes for me in the Variable View View window to remove the variable labels. I want to know how to remove them with syntax. Below is my code. The value labels have been repeated for the string variables because they vary in width. My main query concerns the loop with the vector. Please note that the variable labels have not been removed, as shown in the output from DISPLAY LABELS command, and that a rogue variable named v has a variable label of "(#I) ' '". get file='c:\data\spss\ckcs220\sdatac19.sav'. value labels course. value labels facultid. value labels q17prog. value labels id to surveyc q01a to q16age q18coop to q25comut. missing values id to surveyc q01a to q16age q18coop to q25comut (). string v (A10). VECTOR V=id to surveyc. LOOP #I=1 TO 3. VAR LABELS V(#I) ' '. END LOOP. display labels. Output folllws: Variable Labels Variable Position Label id 1 Student ID location 2 Project Location surveyc 3 Survey Category ... Many lines omitted ... v 41 (#I) ' ' |
The evidence of your example says that VAR LABELS cannot be
defined in a loop with an index. Since the label does not *have* to be included in quotes, the command took the name "V" as a new variable, since it was followed by a character "(" not allowed in a name. An easy way to lose all the characteristics is to say, for instance, Compute IDN = ID. Then save IDN instead of saving ID. -- Rich Ulrich ---------------------------------------- > Date: Wed, 2 Mar 2011 20:44:07 -0800 > From: [hidden email] > Subject: Re: Stripping off attributes: Variable labels in a vector loop > To: [hidden email] > > I know that removing the attributes of variables removes meaning from the > data. My objective is to present my students with a naked file and to ask > them to add the variable labels, value labels, missing values and other > attributes so that they will understand what is required to make a data file > understandable. > > It took only a couple of minutes for me in the Variable View View window to > remove the variable labels. I want to know how to remove them with syntax. > > Below is my code. The value labels have been repeated for the string > variables because they vary in width. My main query concerns the loop with > the vector. Please note that the variable labels have not been removed, as > shown in the output from DISPLAY LABELS command, and that a rogue variable > named > v has a variable label of "(#I) ' '". > > get file='c:\data\spss\ckcs220\sdatac19.sav'. > value labels course. > value labels facultid. > value labels q17prog. > value labels id to surveyc q01a to q16age q18coop to q25comut. > missing values id to surveyc q01a to q16age q18coop to q25comut (). > > string v (A10). > VECTOR V=id to surveyc. > LOOP #I=1 TO 3. > VAR LABELS V(#I) ' '. > END LOOP. > ===================== 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 spruce18b
This should be possible with python. There are python codes that read variable lables and value lables. You simply have to adapt the python code. A good start would be like that:
BEGIN PROGRAM. import spss spss.Submit(["GET FILE='C:/<path>/file.sav'."]) FileN=spss.GetVariableCount() i = 1 while i < FileN: label = spss.GetVariableLabel(i) level = spss.GetVariableMeasurementLevel(i) i+=1 END PROGRAM.
Dr. Frank Gaeth
|
In reply to this post by spruce18b
If you want a raw data set to build up into a saved file from scratch, have
a look at the step-by-step tutorials in Block 1 on my website. (See: http://surveyresearch.weebly.com/block-1-from-questionnaire-to-spss-saved-fi le.html ) They start even further back by getting students to complete a short questionnaire, transcribe the data and then run SPSS on their own data, but usually on a cumulative data set using the same questionnaire, before progressing to defining a few variables, reading data from actual surveys (eg British Social Attitudes) and creating their own *.sav files. If it's not too complicated, you could always use SPSS to WRITE out a complete or partial raw data set from your survey exemplar. John Hall [hidden email] www.surveyresearch.weebly.com -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of spruce18b Sent: 03 March 2011 05:44 To: [hidden email] Subject: Re: Stripping off attributes: Variable labels in a vector loop I know that removing the attributes of variables removes meaning from the data. My objective is to present my students with a naked file and to ask them to add the variable labels, value labels, missing values and other attributes so that they will understand what is required to make a data file understandable. It took only a couple of minutes for me in the Variable View View window to remove the variable labels. I want to know how to remove them with syntax. Below is my code. The value labels have been repeated for the string variables because they vary in width. My main query concerns the loop with the vector. Please note that the variable labels have not been removed, as shown in the output from DISPLAY LABELS command, and that a rogue variable named v has a variable label of "(#I) ' '". get file='c:\data\spss\ckcs220\sdatac19.sav'. value labels course. value labels facultid. value labels q17prog. value labels id to surveyc q01a to q16age q18coop to q25comut. missing values id to surveyc q01a to q16age q18coop to q25comut (). string v (A10). VECTOR V=id to surveyc. LOOP #I=1 TO 3. VAR LABELS V(#I) ' '. END LOOP. display labels. Output folllws: Variable Labels Variable Position Label id 1 Student ID location 2 Project Location surveyc 3 Survey Category ... Many lines omitted ... v 41 (#I) ' ' -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Stripping-off-attributes-Varia ble-labels-in-a-vector-loop-tp3405980p3407492.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 |
Administrator
|
In reply to this post by spruce18b
At the risk of asking a silly question, why don't you just save the file as .CSV, or some other format that does not include labels, and then import that file? E.g.,
* Strip all variable and value labels from a file. get file = "C:\Program Files\SPSSInc\PASWStatistics18\Samples\English\Cars.sav". * Write data to a .CSV file -- or some other format you like * that does not save labels. SAVE TRANSLATE OUTFILE='C:\temp\Cars.csv' /TYPE=CSV /MAP /REPLACE /FIELDNAMES /CELLS=VALUES. * Now import the .CSV file . GET DATA /TYPE=TXT /FILE="C:\Temp\Cars.csv" /DELCASE=LINE /DELIMITERS="," /ARRANGEMENT=DELIMITED /FIRSTCASE=2 /IMPORTCASE=ALL /VARIABLES= mpg F4.1 engine F4.1 horse F3.0 weight F4.0 accel F4.1 year F2.0 origin F1.0 cylinder F1.0 filter_$ F1.0. CACHE. EXECUTE. HTH.
--
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/). |
In reply to this post by spruce18b
Here is a quick way to eliminate variable
and value labels. It relies on the SPSSINC SELECT VARIABLES extension
command available from the SPSS Community (www.ibm.com/developerworks/spssdevcentral).
That command is used to define two macros. The first one lists
all numeric variables; the second one lists all variables, separating the
names with "/".
SPSSINC SELECT VARIABLES MACRONAME="!numeric" /PROPERTIES TYPE=NUMERIC. SPSSINC SELECT VARIABLES MACRONAME="!all" /OPTIONS SEPARATOR="/". These commands then use those macros to clear the properties. variable labels !all. value labels !numeric. The wrinkle is that for a group of variables on VALUE LABELS, they all have to be the same type. If there are string variables, you could generate a similar !string macro, but you would need to do this for each variable length. SELECT VARIABLES can take a list of variables for this process. It has a dialog box interface that you can install along with the command. This could all be done with a short Python program if you know how to write that. HTH, Jon Peck Senior Software Engineer, IBM [hidden email] 312-651-3435 From: spruce18b <[hidden email]> To: [hidden email] Date: 03/02/2011 09:46 PM Subject: Re: [SPSSX-L] Stripping off attributes: Variable labels in a vector loop Sent by: "SPSSX(r) Discussion" <[hidden email]> I know that removing the attributes of variables removes meaning from the data. My objective is to present my students with a naked file and to ask them to add the variable labels, value labels, missing values and other attributes so that they will understand what is required to make a data file understandable. It took only a couple of minutes for me in the Variable View View window to remove the variable labels. I want to know how to remove them with syntax. Below is my code. The value labels have been repeated for the string variables because they vary in width. My main query concerns the loop with the vector. Please note that the variable labels have not been removed, as shown in the output from DISPLAY LABELS command, and that a rogue variable named v has a variable label of "(#I) ' '". get file='c:\data\spss\ckcs220\sdatac19.sav'. value labels course. value labels facultid. value labels q17prog. value labels id to surveyc q01a to q16age q18coop to q25comut. missing values id to surveyc q01a to q16age q18coop to q25comut (). string v (A10). VECTOR V=id to surveyc. LOOP #I=1 TO 3. VAR LABELS V(#I) ' '. END LOOP. display labels. Output folllws: Variable Labels Variable Position Label id 1 Student ID location 2 Project Location surveyc 3 Survey Category ... Many lines omitted ... v 41 (#I) ' ' -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Stripping-off-attributes-Variable-labels-in-a-vector-loop-tp3405980p3407492.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 |
Here's a simpler version that handles both
string and numeric. VALUE LABELS actually supports the same construct
as VARIABLE LABELS.
SPSSINC SELECT VARIABLES MACRONAME="!all" /OPTIONS SEPARATOR="/". VARIABLE LABELS !all. VALUE LABELS !all. Jon Peck Senior Software Engineer, IBM [hidden email] 312-651-3435 From: Jon K Peck/Chicago/IBM@IBMUS To: [hidden email] Date: 03/03/2011 11:05 AM Subject: Re: [SPSSX-L] Stripping off attributes: Variable labels in a vector loop Sent by: "SPSSX(r) Discussion" <[hidden email]> Here is a quick way to eliminate variable and value labels. It relies on the SPSSINC SELECT VARIABLES extension command available from the SPSS Community (www.ibm.com/developerworks/spssdevcentral). That command is used to define two macros. The first one lists all numeric variables; the second one lists all variables, separating the names with "/". SPSSINC SELECT VARIABLES MACRONAME="!numeric" /PROPERTIES TYPE=NUMERIC. SPSSINC SELECT VARIABLES MACRONAME="!all" /OPTIONS SEPARATOR="/". These commands then use those macros to clear the properties. variable labels !all. value labels !numeric. The wrinkle is that for a group of variables on VALUE LABELS, they all have to be the same type. If there are string variables, you could generate a similar !string macro, but you would need to do this for each variable length. SELECT VARIABLES can take a list of variables for this process. It has a dialog box interface that you can install along with the command. This could all be done with a short Python program if you know how to write that. HTH, Jon Peck Senior Software Engineer, IBM [hidden email] 312-651-3435 From: spruce18b <[hidden email]> To: [hidden email] Date: 03/02/2011 09:46 PM Subject: Re: [SPSSX-L] Stripping off attributes: Variable labels in a vector loop Sent by: "SPSSX(r) Discussion" <[hidden email]> I know that removing the attributes of variables removes meaning from the data. My objective is to present my students with a naked file and to ask them to add the variable labels, value labels, missing values and other attributes so that they will understand what is required to make a data file understandable. It took only a couple of minutes for me in the Variable View View window to remove the variable labels. I want to know how to remove them with syntax. Below is my code. The value labels have been repeated for the string variables because they vary in width. My main query concerns the loop with the vector. Please note that the variable labels have not been removed, as shown in the output from DISPLAY LABELS command, and that a rogue variable named v has a variable label of "(#I) ' '". get file='c:\data\spss\ckcs220\sdatac19.sav'. value labels course. value labels facultid. value labels q17prog. value labels id to surveyc q01a to q16age q18coop to q25comut. missing values id to surveyc q01a to q16age q18coop to q25comut (). string v (A10). VECTOR V=id to surveyc. LOOP #I=1 TO 3. VAR LABELS V(#I) ' '. END LOOP. display labels. Output folllws: Variable Labels Variable Position Label id 1 Student ID location 2 Project Location surveyc 3 Survey Category ... Many lines omitted ... v 41 (#I) ' ' -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Stripping-off-attributes-Variable-labels-in-a-vector-loop-tp3405980p3407492.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 |
In reply to this post by spruce18b
If you go into the main site and check Block 1 in the left menu, it should
be all there. I thought I might have left off a couple of letters http://surveyresearch.weebly.com/block-1-from-questionnaire-to-spss-saved-fi le , but you're right: this is a Weebly problem I think. This works: http://surveyresearch.weebly.com/block-1-from-questionnaire-to-spss-saved-fi le.html Could be the SPSSX list server chopped it up a bit. John Hall [hidden email] www.surveyresearch.weebly.com -----Original Message----- From: William Klein [mailto:[hidden email]] Sent: 03 March 2011 18:58 To: [hidden email] Subject: E: Stripping off attributes: Variable labels in a vector loop Hi John, Your Web site is not published. Could you please make it available? Thanks, Bill If you want a raw data set to build up into a saved file from scratch, have a look at the step-by-step tutorials in Block 1 on my website. (See: http://surveyresearch.weebly.com/block-1-from-questionnaire-to-spss-saved-fi ===================== 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 |
Hi John, Thanks for the invitation to view your Web site. In Block
1, which syntax for stripping off variable attributes should I look
at? May I use any of your data sets or materials in my course at
Ryerson University, Toronto
Thanks, Bill On 2011 March 4 6:20, John F Hall [via SPSSX Discussion] wrote: If you go into the main site and check Block 1 in the left menu, it should |
In reply to this post by Bruce Weaver
That's funny. We all get headaches over searching for the most complex solution to the problem, never thinking of that really simple solution.
Dr. Frank Gaeth
|
In reply to this post by Jon K Peck
Jon,
Does this get through? I'm mailing this, from Hotmail, to the [hidden email] and to your [hidden email] . I have not received any posts from the list since March 3. My address [hidden email] does receive other mail. Rich Ulrich ===================== 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 |
Got this one, too
Jon Peck Senior Software Engineer, IBM [hidden email] 312-651-3435 From: Rich Ulrich <[hidden email]> To: [hidden email] Date: 03/08/2011 02:06 PM Subject: [SPSSX-L] Is Hotmail being black-holed? Sent by: "SPSSX(r) Discussion" <[hidden email]> Jon, Does this get through? I'm mailing this, from Hotmail, to the [hidden email] and to your [hidden email] . I have not received any posts from the list since March 3. My address [hidden email] does receive other mail. Rich Ulrich ===================== 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 spruce18b
I know this is a little late, but I was able to go into the Variable View of a .sav file, click on the "Label" header, hit the Delete key, and all of the variable labels disappeared. FYI, funny but this didn't work if I did anything else after opening the file.
|
Free forum by Nabble | Edit this page |