SPSS set lables equal to value in column

Viewed 76

As the title says.

What I'm trying to do is a way to set the labels of a column equal to the value in another column.

A     B
1     Car
2     Bike 
3     Van 
1     Car
3     Van 

Column A contains the numeric values. Column B contains the labels.

I want to tell SPSS to take the value 1, and assign it the label "Car" (and so on) as clasically is done manually with:

VALUE LABELS 
1 "Car"
2 "Bike"
3 "Van".
Execute.
1 Answers

The syntax below will automatically create a new syntax that adds the value labels as you described.

Before starting, I'm recreating the sample data you posted to demonstrate on:

data list list/A  (f1)   B (a10).
begin data
1     "Car"
2     "Bike"
3     "Van"
1    " Car"
3     "Van" 
end data.
dataset name orig.

Now we get to work:

* first we aggregate the data to get only one line for every value/label pair.
dataset declare agg.
aggregate out=agg /break A B /nn=n.
dataset activate agg.

* now we use the data to create a syntax file with the value label commands.
string cat (a50).
compute cat=concat('"', B, '"').
write out="yourpath\my labels syntax.sps" /"add value labels A ", A, cat, ".".
execute.

* getting back to the original data we can now execute the syntax.
dataset activate orig.
insert file="yourpath\my labels syntax.sps".
Related