outputting variable and value labels to sytnax

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

outputting variable and value labels to sytnax

Putnick, Diane (NIH/NICHD) [E]

Hi SPSS Gurus,

 

Is there an easy way to take the variable and value labels that are already assigned to a dataset and output them to a syntax file?  I’ve gotten the file information, but can’t figure out an easy way to copy the info I need to a syntax file. 

 

Thanks!

Diane

 

Reply | Threaded
Open this post in threaded view
|

Re: outputting variable and value labels to sytnax

Rick Oliver-3
Why do you need to do this? You can use APPLY DICTIONARY to apply variable and value labels (and other attributes) from one file to another file.


From: "Putnick, Diane (NIH/NICHD) [E]" <[hidden email]>
To: [hidden email]
Date: 09/29/2010 10:14 AM
Subject: outputting variable and value labels to sytnax
Sent by: "SPSSX(r) Discussion" <[hidden email]>





Hi SPSS Gurus,
 
Is there an easy way to take the variable and value labels that are already assigned to a dataset and output them to a syntax file?  I’ve gotten the file information, but can’t figure out an easy way to copy the info I need to a syntax file.  
 
Thanks!
Diane
 

Reply | Threaded
Open this post in threaded view
|

Re: outputting variable and value labels to sytnax

Putnick, Diane (NIH/NICHD) [E]

That helps.  I wanted to apply the attributes of one file to another, but not all of the variables are overlapping.  I was just going to edit the syntax once I had it.  Will apply dictionary work if the datasets contain some differing variables?

 

Thanks!

Diane

 

From: Rick Oliver [mailto:[hidden email]]
Sent: Wednesday, September 29, 2010 11:31 AM
To: Putnick, Diane (NIH/NICHD) [E]
Cc: [hidden email]
Subject: Re: outputting variable and value labels to sytnax

 

Why do you need to do this? You can use APPLY DICTIONARY to apply variable and value labels (and other attributes) from one file to another file.

From:

"Putnick, Diane (NIH/NICHD) [E]" <[hidden email]>

To:

[hidden email]

Date:

09/29/2010 10:14 AM

Subject:

outputting variable and value labels to sytnax

Sent by:

"SPSSX(r) Discussion" <[hidden email]>

 





Hi SPSS Gurus,
 
Is there an easy way to take the variable and value labels that are already assigned to a dataset and output them to a syntax file?  I’ve gotten the file information, but can’t figure out an easy way to copy the info I need to a syntax file.  
 
Thanks!
Diane
 

Reply | Threaded
Open this post in threaded view
|

Re: outputting variable and value labels to sytnax

Rick Oliver-3
Yes.  By default, variables in the target file that don't exist in the source file are ignored. You can also apply attributes from one variable in the source file to a variable of a different name in the target file, but you can only do this one at a time (a separate Apply Dictionary command for each variable with a different name in the two files).


From: "Putnick, Diane (NIH/NICHD) [E]" <[hidden email]>
To: [hidden email]
Date: 09/29/2010 10:36 AM
Subject: Re: outputting variable and value labels to sytnax
Sent by: "SPSSX(r) Discussion" <[hidden email]>





That helps.  I wanted to apply the attributes of one file to another, but not all of the variables are overlapping.  I was just going to edit the syntax once I had it.  Will apply dictionary work if the datasets contain some differing variables?
 
Thanks!
Diane
 
From: Rick Oliver [mailto:oliverr@...]
Sent:
Wednesday, September 29, 2010 11:31 AM
To:
Putnick, Diane (NIH/NICHD) [E]
Cc:
[hidden email]
Subject:
Re: outputting variable and value labels to sytnax

 
Why do you need to do this? You can use APPLY DICTIONARY to apply variable and value labels (and other attributes) from one file to another file.

From: "Putnick, Diane (NIH/NICHD) [E]" <[hidden email]>
To: [hidden email]
Date: 09/29/2010 10:14 AM
Subject: outputting variable and value labels to sytnax
Sent by: "SPSSX(r) Discussion" <[hidden email]>

 






Hi SPSS Gurus,

 
Is there an easy way to take the variable and value labels that are already assigned to a dataset and output them to a syntax file?  I’ve gotten the file information, but can’t figure out an easy way to copy the info I need to a syntax file.  

 
Thanks!

Diane

 

Reply | Threaded
Open this post in threaded view
|

Re: outputting variable and value labels to sytnax

Govind Acharya-2
In reply to this post by Putnick, Diane (NIH/NICHD) [E]
I've actually wanted to know if there is a way to do this as well.� Is there a way to use Python to output this information?� In stata, it's pretty easy to do but I haven't found a way in SPSS.�

On 9/29/2010 11:34 AM, Putnick, Diane (NIH/NICHD) [E] wrote:

That helps.� I wanted to apply the attributes of one file to another, but not all of the variables are overlapping.� I was just going to edit the syntax once I had it.� Will apply dictionary work if the datasets contain some differing variables?

Thanks!

Diane

From: Rick Oliver [[hidden email]]
Sent: Wednesday, September 29, 2010 11:31 AM
To: Putnick, Diane (NIH/NICHD) [E]
Cc: [hidden email]
Subject: Re: outputting variable and value labels to sytnax

Why do you need to do this? You can use APPLY DICTIONARY to apply variable and value labels (and other attributes) from one file to another file.

From:

"Putnick, Diane (NIH/NICHD) [E]" [hidden email]

To:

[hidden email]

Date:

09/29/2010 10:14 AM

Subject:

outputting variable and value labels to sytnax

Sent by:

"SPSSX(r) Discussion" [hidden email]





Hi SPSS Gurus,

Is there an easy way to take the variable and value labels that are already assigned to a dataset and output them to a syntax file? � I’ve gotten the file information, but can’t figure out an easy way to copy the info I need to a syntax file. �

Thanks!
Diane


--
Govind Acharya
Research Analyst
Ithaca College
217 Peggy R. Williams Center
953 Danby Rd.
Ithaca, NY 14850-7002

phone: (607) 274-3876
fax: (607) 274-1861
Reply | Threaded
Open this post in threaded view
|

Re: outputting variable and value labels to sytnax

Bruce Weaver
Administrator
In reply to this post by Putnick, Diane (NIH/NICHD) [E]
Diane Putnick wrote
That helps.  I wanted to apply the attributes of one file to another, but not all of the variables are overlapping.  I was just going to edit the syntax once I had it.  Will apply dictionary work if the datasets contain some differing variables?

Thanks!
Diane
Read the fine manual, Diane.  Here are the first few lines of the syntax chart:


APPLY DICTIONARY FROM [{'savfile'|'dataset'}]
                       {*                  }  
 [/SOURCE VARIABLES = varlist]
 [/TARGET VARIABLES = varlist]
 [/NEWVARS]
etc

And here is some info from the Help page on the /SOURCE sub-command:

The SOURCE subcommand is used to specify variables in the source file from which to apply variable definition attributes. The TARGET subcommand is used to specify variables in the active dataset to which to apply variable definition attributes.

• All variables specified in the SOURCE subcommand must exist in the source file.

• If the TARGET subcommand is specified without the SOURCE subcommand, all variables specified must exist in the source file.

• If the NEWVARS subcommand is specified, variables that are specified in the SOURCE subcommand that exist in the source file but not in the target file will be created in the target file as new variables using the variable definition attributes (variable and value labels, missing values, etc.) from the source variable.

• For variables with matching name and type, variable definition attributes from the source variable are applied to the matching target variable.

• If both SOURCE and TARGET are specified, the SOURCE subcommand can specify only one variable. Variable definition attributes from that single variable in the SOURCE subcommand are applied to all variables of the matching type. When applying the attributes of one variable to many variables, all variables specified in the SOURCE and TARGET subcommands must be of the same type.

• For variables with matching names but different types, only variable labels are applied to the target variables.

Example
APPLY DICTIONARY from *
  /SOURCE VARIABLES = var1
  /TARGET VARIABLES = var2 var3 var4
  /NEWVARS.

• Variable definition attributes for var1 in the active dataset are copied to var2, var3, and var4 in the same dataset if they have a matching type.

• Any variables specified in the TARGET subcommand that do not already exist are created, using the variable definition attributes of the variable specified in the SOURCE subcommand.

Example
APPLY DICTIONARY from “lastmonth.sav”
  /SOURCE VARIABLES = var1, var2, var3.

• Variable definition attributes from the specified variables in the source dataset are applied to the matching variables in the active dataset.

• For variables with matching names but different types, only variable labels from the source variable are copied to the target variable.

• In the absence of a NEWVARS subcommand, no new variables will be created.

--
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/).
Reply | Threaded
Open this post in threaded view
|

Re: outputting variable and value labels to sytnax

John F Hall
In reply to this post by Putnick, Diane (NIH/NICHD) [E]

Do you have the original syntax files or the output files for the previous file?  If so, you can copy the syntax from either and edit it to suit.
 
----- Original Message -----
Sent: Wednesday, September 29, 2010 5:34 PM
Subject: Re: outputting variable and value labels to sytnax

That helps.  I wanted to apply the attributes of one file to another, but not all of the variables are overlapping.  I was just going to edit the syntax once I had it.  Will apply dictionary work if the datasets contain some differing variables?

 

Thanks!

Diane

 

From: Rick Oliver [mailto:[hidden email]]
Sent: Wednesday, September 29, 2010 11:31 AM
To: Putnick, Diane (NIH/NICHD) [E]
Cc: [hidden email]
Subject: Re: outputting variable and value labels to sytnax

 

Why do you need to do this? You can use APPLY DICTIONARY to apply variable and value labels (and other attributes) from one file to another file.

From:

"Putnick, Diane (NIH/NICHD) [E]" <[hidden email]>

To:

[hidden email]

Date:

09/29/2010 10:14 AM

Subject:

outputting variable and value labels to sytnax

Sent by:

"SPSSX(r) Discussion" <[hidden email]>

 





Hi SPSS Gurus,
 
Is there an easy way to take the variable and value labels that are already assigned to a dataset and output them to a syntax file?  I’ve gotten the file information, but can’t figure out an easy way to copy the info I need to a syntax file.  
 
Thanks!
Diane
 

Reply | Threaded
Open this post in threaded view
|

Re: outputting variable and value labels to sytnax

Albert-Jan Roskam
In reply to this post by Putnick, Diane (NIH/NICHD) [E]
Hi,

Hi,

AFAIK, Apply dictionary works fine, except when string vars of source vs. target file are of differing length. But that might have changed in newer versions of spss. The Python code below generates an sps file of all the the variable and value labels of the open data file. It's untested (I don't have spss here), but I think it's correct.

import spssaux, os

cmds = ""
for v in spssaux.VariableDict():
    if v.VariableLabel:
        cmds += "variable label %s '%s'.%s" \
          % (v.VariableName, v.VariableLabel, os.linesep)
    if v.ValueLabels:
        cmds += "value labels %s" + "  %s".join([str(k) + " '" + \
          val + "'" for k, val in v.ValueLabels.iteritems()]) \
          % (v.VariableName, os.linesep) + "."
with open("d:/temp/mylabels.sps", "wb") as f:
    f.write(cmds)
 
Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



From: "Putnick, Diane (NIH/NICHD) [E]" <[hidden email]>
To: [hidden email]
Sent: Wed, September 29, 2010 5:34:41 PM
Subject: Re: [SPSSX-L] outputting variable and value labels to sytnax

That helps.  I wanted to apply the attributes of one file to another, but not all of the variables are overlapping.  I was just going to edit the syntax once I had it.  Will apply dictionary work if the datasets contain some differing variables?

 

Thanks!

Diane

 

From: Rick Oliver [mailto:[hidden email]]
Sent: Wednesday, September 29, 2010 11:31 AM
To: Putnick, Diane (NIH/NICHD) [E]
Cc: [hidden email]
Subject: Re: outputting variable and value labels to sytnax

 

Why do you need to do this? You can use APPLY DICTIONARY to apply variable and value labels (and other attributes) from one file to another file.

From:

"Putnick, Diane (NIH/NICHD) [E]" <[hidden email]>

To:

[hidden email]

Date:

09/29/2010 10:14 AM

Subject:

outputting variable and value labels to sytnax

Sent by:

"SPSSX(r) Discussion" <[hidden email]>

 





Hi SPSS Gurus,
 
Is there an easy way to take the variable and value labels that are already assigned to a dataset and output them to a syntax file?  I’ve gotten the file information, but can’t figure out an easy way to copy the info I need to a syntax file.  
 
Thanks!
Diane
 


Reply | Threaded
Open this post in threaded view
|

Re: outputting variable and value labels to sytnax

Putnick, Diane (NIH/NICHD) [E]
In reply to this post by Putnick, Diane (NIH/NICHD) [E]

Thanks for all the advice!  Because I really wanted to be able to keep the syntax so I could send it to a colleague, I ended up copying the tables from File Info into Excel, deleting the columns I didn’t needs, and then pasting it from there into the syntax window.  Then I just had to add in the quotation marks around the labels.  So that’s a work-around.  I will try the python script next time.

 

Thanks!

Diane

 

Reply | Threaded
Open this post in threaded view
|

Re: outputting variable and value labels to sytnax

John F Hall
Diane
 
Next time you have a new SPSS job, best to use syntax or PASTE or follow Jacqueline Collier's advice about audit trails from the journal files.  Her book Using SPSS Syntax is aimed at GUI users in attempt to wean them over to syntx.  It's listed among the recommended SPSS textbooks on my website where you will also find a stack of syntax-based tutorials for SPSS as well, mainly entry-level and for processing and analysing data from (real) questionnaire surveys: so far not a single equation in well over 100 pages, but my next batch in the Analysing one variable section concerns interval scale variables.
 
----- Original Message -----
Sent: Thursday, September 30, 2010 2:36 PM
Subject: Re: outputting variable and value labels to sytnax

Thanks for all the advice!  Because I really wanted to be able to keep the syntax so I could send it to a colleague, I ended up copying the tables from File Info into Excel, deleting the columns I didn’t needs, and then pasting it from there into the syntax window.  Then I just had to add in the quotation marks around the labels.  So that’s a work-around.  I will try the python script next time.

 

Thanks!

Diane