Deleting Value Labels in SPSS

8.6k views Asked by At

I imported data from survey monkey into spss and survey monkey automatically assigns values and value labels. My values and labels are currently something like this:

1 "Married" 2 "Single" 3 "777" 4 "999"

I re-coded variables so that 3=777 and 4=999. Then I set 777 and 999 to missing. I then used ADD VALUE LABELS to add the 777= "Refused" and 999= "Don't know". How do I use syntax to delete the Value and Value Labels for 3 and 4? These are no longer true since I re-coded values 3 and 4. I know I can use VALUE LABELS to delete all my values and labels but I would have to specify all my categories which would be tedious. Ideally I would want to re-code the 3 and 4 values, add values labels for the new 777 and 999 values and delete the old 3 and 4. If I only had a few variables I would consider doing it a different way but I want to write syntax that I could use for a list of about 100 variables. I will also be pulling data from survey monkey on a weekly basis and would like to have the syntax file to rename, recode, and add value labels ready to go each time I pull the data.

2

There are 2 answers

0
Jignesh Sutar On

I don't believe there is a way to delete specific value labels for specific values only. So the workaround is to explicitly set the values for the entire set of values:

DATA LIST FREE / MS.
BEGIN DATA
1 2 3 4
END DATA.

/* 1. Original values labels */.
VALUE LABELS MS 1 "Sinlge" 2 "Married" 3 "777" 4 "999".
CTABLES /TABLE MS[C].

/* 2. Recode values and re-label - Note values 3 and 4 are still assigned values but they happen to be blank as they are being registered by CTABLES */.
RECODE MS (3=777) (4=999).
ADD VALUE LABELS MS 3 "" 4 "" 777 "Refused" 999 "Unknown".
CTABLES /TABLE MS[C].

/* 3. Workaround is to assign explicitly entire set of values */.
VALUE LABELS MS 1 "Sinlge" 2 "Married" 777 "Refused" 999 "Unknown".
CTABLES /TABLE MS[C].

Update:

Well, nothing is impossible in the realms of computing. Raynald Levesque outlines a workaround solution here. And Ruben Geert van den Berg provides a python solution on his website also.

0
johnwhite On

That's can make with python begin-end program block inside SPSS syntax:

DATA LIST FREE / MS (F1.0).
BEGIN DATA
END DATA.

VALUE LABELS MS 1 "Married" 2 "Single" 3 "777" 4 "999".
ADD VALUE LABELS MS 777 "Refused" 999 "Don't know".

BEGIN PROGRAM.
import spss

qst='MS'
values=[3,4]
with spss.DataStep():
    datasetObj=spss.Dataset();varObj = datasetObj.varlist[qst];valObj=varObj.valueLabels
    print 'Before:',valObj
    for i in values: 
        try:
            del valObj[i]
        except:
            continue   
    print 'After:',valObj
END PROGRAM.

Output Log:

Before: {1.0: 'Married', 2.0: 'Single', 3.0: '777', 4.0: '999', 999.0: "Don't know", 777.0: 'Refused'} 
After: {1.0: 'Married', 2.0: 'Single', 777.0: 'Refused', 999.0: "Don't know"}