Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Importing value labels from excel to spss

1,757 views
Skip to first unread message

Filip Van Droogenbroeck

unread,
Jul 24, 2014, 12:35:51 PM7/24/14
to
Dear SPSS users,

I have an excel file which is structured like this:
Variable1 Label1 Value1
Variable1 Label2 Value2
Variable1 Label3 Value3
Variable2 Label1 Value1
Variable3 Label1 Value1
Variable3 Label2 Value2

Is there a way to import this into SPSS?
Is there a way to get it into this:

VALUE LABELS
Variable1 {value1} "Label1"
{value2} "Label2"
{value3} "Label3" /
Variable2 {value1} "Label1" /
Variable3 {value1} "Label1"
{value2} "Label2".

?

Kind regards,
Filip Van Droogenbroeck

Ruben Geert van den Berg

unread,
Jul 24, 2014, 12:50:47 PM7/24/14
to
Sure. There's two main options.

1) Have Python read the .xls file and send ADD VALUE LABELS commands to SPSS by spss.Submit using the xls cell contents

2) Read the xls file into SPSS => declare a long empty string variable => CONCAT lines of ADD VALUE LABELS commands into this string variable => save this variable as text with ".sps" as file extension instead of ".txt" => use INSERT FILE for running the syntax.

You might want to look into

http://www.spss-tutorials.com/xlrd-python/
http://www.spss-tutorials.com/concatenate/
http://www.spss-tutorials.com/insert/

HTH,

Ruben

P.s. as this question comes by more often, I might write a tutorial with the required Python syntax on it.

Filip Van Droogenbroeck

unread,
Jul 25, 2014, 5:57:56 AM7/25/14
to
Hi Ruben,

This question has been around a few times:
For example:
https://groups.google.com/forum/#!topic/comp.soft-sys.stat.spss/AQpTj_MOHpI

But nobody responded with a working example; A tutorial would be much appreciated. I think with the methods you suggest the problem remains how to create an automatic loop that knows when to stop concatenating when a new variable appears. Because

Variable1 Label1 Value1
Variable1 Label2 Value2
Variable1 Label3 Value3
Variable2 Label1 Value1
Variable3 Label1 Value1
Variable3 Label2 Value2

Should become
value labels variable1 value1 "label1" value2 "label2" value3 "label3".
value labels variable2 value1 "label1".
value labels variable3 value1 "label1" value2 "label2".

And not
value labels variable1 value1 "label1".
value labels variable1 value2 "label2".
value labels variable1 value3 "label3".
...

The latter wouldn't work.

cheers,
F


Op donderdag 24 juli 2014 18:50:47 UTC+2 schreef Ruben Geert van den Berg:

David Marso

unread,
Jul 25, 2014, 9:47:51 AM7/25/14
to
" the problem remains how to create an automatic loop that knows when to stop concatenating when a new variable appears"...
NO!
See ADD VALUE LABELS!
--

Ruben Geert van den Berg

unread,
Jul 25, 2014, 10:53:14 AM7/25/14
to
Yeah, please note the difference between the VALUE LABELS and ADD VALUE LABELS commands.

Also, see http://www.spss-tutorials.com/changing-variable-properties-5-variable-and-value-labels/#vallabs.

But I still recommend the Python approach since I think it's cleaner and shorter. I'll post a working example if I can find the time.

The CONCAT and INSERT approach is a little more "old skool" than I like...

Best,

Ruben

Filip Van Droogenbroeck

unread,
Jul 25, 2014, 3:00:22 PM7/25/14
to
Aha yes I see. Wish I had seen it earlier
Spent the whole afternoon programming a script in perl which transformed the variables :)

Tnx for the help!
cheers,
F


Op vrijdag 25 juli 2014 16:53:14 UTC+2 schreef Ruben Geert van den Berg:

Ruben Geert van den Berg

unread,
Jul 26, 2014, 3:10:38 AM7/26/14
to
Hi Filip,

For working examples (including Excel test data) of the two approaches I suggested, see http://www.spss-tutorials.com/apply-dictionary-information-from-excel/.

Both of them may take you (much) less than a whole afternoon ;-)

Hope you find them helpful but suggestions are highly appreciated as well.

Best,

Ruben
0 new messages