create syntax (var and value labels) from sav file

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

create syntax (var and value labels) from sav file

Brian Moore-7
create syntax (var and value labels) from sav file

Hi all-

I get survey data files from a vendor who used to allow download of csv plus syntax to import and label or  sav files.  But now they have “enhanced” their tool to no longer provide syntax files.

So Im looking for a least possible retyping solution to having syntax file that addresses inevitable “small” edits [for example occasional unrecognized characters like apostrophes & in particular labeling of matrix questions <their default is to include the question text before each statement in  the matrix; often unwieldy but easy to change with find and replace in a syntax file>] from the vendor. 

Being able to create a syntax file from an sav file seems logically possible and a useful solution, but I dont know if it is possible or how to proceed (dictionary commands were as close as I got in searching the data management handbook, but not quite what I was hoping for).

Im using v15 & will not have access to python solutions (not allowed / supported by our IT department at present).

Suggestions appreciated.

Regards,

Brian 

PS I think a worst case for variable labels is not too terrible (copying whole variable view to excel & editing there to make something paste able to my own syntax file), but dont think it would be possible to tackle changes to value labels this way.  Seems like 1 x 1 & retyping would be only solution.

Brian Moore
Market Research Manager
WorldatWork
14040 N. Northsight Blvd.
Scottsdale, AZ 85260 USA
Tel: 480-304
-6832 Fax: 480-483-8352
E-mail: [hidden email]
www.worldatwork.org

UPCOMING CONFERENCES:
Total Rewards 2010
May 16-19  |  Dallas / Ft.Worth, TX

The GTA Rewards Association
Total Rewards 2010 Canadian Conference
In partnership with the Ottawa Region Rewards Association and WorldatWork
Sept. 14-16 | Toronto

Reply | Threaded
Open this post in threaded view
|

Re: create syntax (var and value labels) from sav file

Albert-Jan Roskam
Hi,
 
Does the code below do what you want? I pasted some output below also, based on the employee data file.
 
begin program.
""" Generate value labels and variable labels based on a sav file """
import spss, spssaux
varlabs, vallabs = "", ""
for v in spssaux.VariableDict():
  varlabs += "variable label %s '%s'.\n" % (v.VariableName, v.VariableLabel)
  vallab = "value labels " + v.VariableName + "\n"
  labels = v.ValueLabels
  if labels:
    for k in sorted(labels.keys()):
      vallab += " %s '%s'\n" % (str(k), labels[k])
    vallabs += vallab + ".\n"
syntax = open("d:/temp/syntax.sps", "wb")
syntax.write(varlabs + vallabs)
syntax.close()
end program.

Cheers!!
Albert-Jan
 
** code generated:.
variable label id 'Employee Code'.
variable label gender 'Gender'.
variable label bdate 'Date of Birth'.
variable label educ 'Educational Level (years)'.
variable label jobcat 'Employment Category'.
variable label salary 'Current Salary'.
variable label salbegin 'Beginning Salary'.
variable label jobtime 'Months since Hire'.
variable label prevexp 'Previous Experience (months)'.
variable label minority 'Minority Classification'.
value labels educ
 0 '0 (Missing)'
 12 '12'
 14 '14'
 15 '15'
 16 '16'
 17 '17'
 18 '18'
 19 '19'
 20 '20'
 21 '21'
 8 '8'
.
value labels jobcat
 0 '0 (Missing)'
 1 'Clerical'
 2 'Custodial'
 3 'Manager'
.
value labels salary
 0 'missing'
.
value labels salbegin
 0 'missing'
.
value labels jobtime
 0 'missing'
.
value labels prevexp
 0 'missing'
.
value labels minority
 0 'No'
 1 'Yes'
 9 '9 (Missing)'
.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the face of ambiguity, refuse the temptation to guess.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Tue, 3/2/10, Brian Moore <[hidden email]> wrote:

From: Brian Moore <[hidden email]>
Subject: [SPSSX-L] create syntax (var and value labels) from sav file
To: [hidden email]
Date: Tuesday, March 2, 2010, 1:05 AM

Hi all-

I get survey data files from a vendor who used to allow download of csv plus syntax to import and label or  sav files.  But now they have “enhanced” their tool to no longer provide syntax files.

So Im looking for a least possible retyping solution to having syntax file that addresses inevitable “small” edits [for example occasional unrecognized characters like apostrophes & in particular labeling of matrix questions <their default is to include the question text before each statement in  the matrix; often unwieldy but easy to change with find and replace in a syntax file>] from the vendor. 

Being able to create a syntax file from an sav file seems logically possible and a useful solution, but I dont know if it is possible or how to proceed (dictionary commands were as close as I got in searching the data management handbook, but not quite what I was hoping for).

Im using v15 & will not have access to python solutions (not allowed / supported by our IT department at present).

Suggestions appreciated.

Regards,

Brian 

PS I think a worst case for variable labels is not too terrible (copying whole variable view to excel & editing there to make something paste able to my own syntax file), but dont think it would be possible to tackle changes to value labels this way.  Seems like 1 x 1 & retyping would be only solution.

Brian Moore
Market Research Manager
WorldatWork
14040 N. Northsight Blvd.
Scottsdale, AZ 85260 USA
Tel: 480-304
-6832 Fax: 480-483-8352
E-mail: [hidden email]
www.worldatwork.org

UPCOMING CONFERENCES:
Total Rewards 2010
May 16-19  |  Dallas / Ft.Worth, TX

The GTA Rewards Association
Total Rewards 2010 Canadian Conference
In partnership with the Ottawa Region Rewards Association and WorldatWork
Sept. 14-16 | Toronto