make .sav file from metaData in another .sav file

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

make .sav file from metaData in another .sav file

oggesjolin
Hi!

I'm trying to produce a .sav-file containing the metaData (varNames, varLabels, ValueLabels) for all variables in another .sav file. I'm at a loss. I want to produce a .savFile with three STRING-variables looking like:

colName, ColText, ColValues
--------, -------, ---------
var1     , Gender, 1=Male | 2=Female
var2     , AgeCat, 1=18-25 | 2=26-40 | 3=41-60

... and so on, containing the relevant information from any given SPSS .sav-file

any suggestions?
Thanks
Reply | Threaded
Open this post in threaded view
|

Re: make .sav file from metaData in another .sav file

Andy W
If using V22 or later, you can use the SYSFILE INFO function with OMS to grab the information you want. If on earlier versions, you can accomplish the same after opening the sav file using DISPLAY DICTIONARY.

**************************************************************.
DATASET DECLARE MetaData.
DATASET DECLARE ValueLab.
OMS /SELECT TABLES /IF SUBTYPES='Variable Information' /DESTINATION FORMAT=SAV OUTFILE='MetaData'.
OMS /SELECT TABLES /IF SUBTYPES='Value Labels' /DESTINATION FORMAT=SAV OUTFILE='ValueLab'.
SYSFILE INFO 'C:\Users\axw161530\Desktop\Test.sav'.
*If before V22, use GET FILE, DATASET ACTIVATE, and DISPLAY DICTIONARY in place of SYSFILE INFO.
OMSEND.
**************************************************************.

This places the variables and the value labels into different datasets. To merge them like you want you will have to use CASESTOVARS to flatten the dataset with the value labels. Here is a quick example, although you may want to munge the data differently. (I leave that as an exercise for you though.)

**************************************************************.
DATASET ACTIVATE ValueLab.
SORT CASES BY Var1 Var2 Label.
ALTER TYPE Var1 (A = A100).
RENAME VARIABLES (Var2 = Val).
CASESTOVARS /ID Var1 /GROUPBY = INDEX /DROP Command_ Subtype_ Label_.
DATASET ACTIVATE MetaData.
ALTER TYPE Var1 (A = A100).
SORT CASES BY Var1.
MATCH FILES FILE = * /TABLE = 'ValueLab' /BY Var1.
*DATASET CLOSE ValueLab.
ALTER TYPE Var1 (A = AMIN).
**************************************************************.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: make .sav file from metaData in another .sav file

David Marso
Administrator
In reply to this post by oggesjolin
Here's an approach:
Leaving it to you to code the remaining trivial string concatenation business (if you still think that is a good idea -I don't-).
I don't see that concatenating the value labels into a single string buys you anything and will not waste my time writing the code for it.

NEW FILE.
DATASET CLOSE ALL.
DATA LIST FREE / a b c.
BEGIN DATA
 1 2 3
 4 5 6
END DATA.
VARIABLE LABELS a 'Variable a' b 'Variable b' c 'Variable c'.
VALUE LABELS a 1 'a one' 2 'a two' 4 'a four'
           / b 1 'b one' 2 'b two' 5 'b five'
           / c 1 'c one' 2 'c two' 3 'c three' 6 'c six'.

FREQUENCIES all.


* OMS.
DATASET DECLARE metadata.
DATASET DECLARE varInfo.
OMS
  /SELECT TABLES
  /IF COMMANDS=['File Information'] SUBTYPES=['Variable Values']
  /DESTINATION FORMAT=SAV
   OUTFILE='metadata' VIEWER=YES.

OMS
  /SELECT TABLES
  /IF COMMANDS=['File Information'] SUBTYPES=['Variable Information']
  /DESTINATION FORMAT=SAV
   OUTFILE='varInfo' VIEWER=YES.

DISPLAY DICTIONARY.
OMSEND.
OMSEND.
DATASET ACTIVATE metadata.
DELETE VARIABLES Command_ Subtype_ Label_.
CASESTOVARS ID=Var1 /GROUPBY INDEX.
DATASET ACTIVATE varInfo.
DELETE VARIABLES Command_ Subtype_ Label_.
MATCH FILES FILE metadata / FILE * / BY Var1.
LIST.

oggesjolin wrote
Hi!

I'm trying to produce a .sav-file containing the metaData (varNames, varLabels, ValueLabels) for all variables in another .sav file. I'm at a loss. I want to produce a .savFile with three STRING-variables looking like:

colName, ColText, ColValues
--------, -------, ---------
var1     , Gender, 1=Male | 2=Female
var2     , AgeCat, 1=18-25 | 2=26-40 | 3=41-60

... and so on, containing the relevant information from any given SPSS .sav-file

any suggestions?
Thanks
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: make .sav file from metaData in another .sav file

Art Kendall
In a new syntax window type
APPLY DICTIONARY.

Place your cursor on that string.
Hit the F1 key.  This key is also known as the HELP key on many keyboards.

If that does not come up with the syntax, you may have an old version of SPSS.

Try something like this **untested**
GET FILE ...
COMPUTE KILLER = 1.
SELECT IF KILLER NE 1.
EXECUTE.
SAVE ...
This is one of the rare occasions where EXECUTE may be needed
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: make .sav file from metaData in another .sav file

Jon Peck
In reply to this post by Andy W
SYSFILE INFO (which goes way back), and DISPLAY DICTIONARY give you all the metadata.  CODEBOOK and the Python spss.Dataset class are other alternatives.  But if you are generating syntax from the output, be careful to handle single and double quotes in the labels.  And, of course, APPLY DICTIONARY is a good way to replicate all or portions of a dictionary without needing to generate the metadata syntax.

On Wed, Aug 24, 2016 at 9:08 AM, Andy W <[hidden email]> wrote:
If using V22 or later, you can use the SYSFILE INFO function with OMS to grab
the information you want. If on earlier versions, you can accomplish the
same after opening the sav file using DISPLAY DICTIONARY.

**************************************************************.
DATASET DECLARE MetaData.
DATASET DECLARE ValueLab.
OMS /SELECT TABLES /IF SUBTYPES='Variable Information' /DESTINATION
FORMAT=SAV OUTFILE='MetaData'.
OMS /SELECT TABLES /IF SUBTYPES='Value Labels' /DESTINATION FORMAT=SAV
OUTFILE='ValueLab'.
SYSFILE INFO 'C:\Users\axw161530\Desktop\Test.sav'.
*If before V22, use GET FILE, DATASET ACTIVATE, and DISPLAY DICTIONARY in
place of SYSFILE INFO.
OMSEND.
**************************************************************.

This places the variables and the value labels into different datasets. To
merge them like you want you will have to use CASESTOVARS to flatten the
dataset with the value labels. Here is a quick example, although you may
want to munge the data differently. (I leave that as an exercise for you
though.)

**************************************************************.
DATASET ACTIVATE ValueLab.
SORT CASES BY Var1 Var2 Label.
ALTER TYPE Var1 (A = A100).
RENAME VARIABLES (Var2 = Val).
CASESTOVARS /ID Var1 /GROUPBY = INDEX /DROP Command_ Subtype_ Label_.
DATASET ACTIVATE MetaData.
ALTER TYPE Var1 (A = A100).
SORT CASES BY Var1.
MATCH FILES FILE = * /TABLE = 'ValueLab' /BY Var1.
*DATASET CLOSE ValueLab.
ALTER TYPE Var1 (A = AMIN).
**************************************************************.



-----
Andy W
[hidden email]
http://andrewpwheeler.wordpress.com/
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/make-sav-file-from-metaData-in-another-sav-file-tp5732966p5732967.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD



--
Jon K Peck
[hidden email]

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD