Merging and matching

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

tkaniuka
Posts: 3
Joined: Sun Feb 27, 2011 9:52 pm

Merging and matching

Postby tkaniuka » Mon Jan 16, 2012 3:20 am

Hello:

I have two files, one that list principals from a set of school buildings and the other the teachers. I need to do a one to many match, that is I need a file that for every teacher the principal data is mached as many timea as there are teachers from the same building as the principal. The two files share a master id variable that I can match on. I tried to use the script at the UCLA site http://www.ats.ucla.edu/stat/spss/modules/merge.htm but I always get an error message saying some type of symbol is missing in the script. Below is the script I am trying to run. prin.sav is the principal file and all.sav contains all the teachers. Any ideas? I am very new at this so the most basic of help will be needed. Oh, I am using SPSS 12. Thanks!!!!!


Sub Main

Get FILE="prin.sav".
SORT CASES BY masterSiteID.
SAVE OUTFILE="prin2.sav".

Get FILE="all.sav".
SORT CASES BY masterSiteID.
SAVE OUTFILE="all2.sav".

MATCH FILES FILE="all2.sav" /TABLE="prin2.sav" /BY masterSiteID.
LIST.



End Sub
Analyst Techy
Moderator
Posts: 22
Joined: Mon Apr 27, 2009 2:19 am
Location: Melbourne, Australia

Re: Merging and matching

Postby Analyst Techy » Mon Jan 16, 2012 5:03 am

Hi tkaniuka.

You are trying to run SPSS syntax within a Visual Basic SPSS Script compiler.

Instead try running the SPSS syntax by
1. Opening any SPSS data file, then click on the menu options File>New>Syntax
2. Copy and paste your code
3. Make sure your code includes the full file paths e.g. "D:\Data\DataFile.sav".
4. To run CTRL+A to select the code that you want to run, then click the Play icon to run.
Analyst Techy

NOTES:
Any solutions I provide on this forum are free of charge, donations go towards the maintenance of the unaffiliated SPSS forum.
tkaniuka
Posts: 3
Joined: Sun Feb 27, 2011 9:52 pm

Re: Merging and matching

Postby tkaniuka » Mon Jan 16, 2012 2:35 pm

Hi Tried the following in syntax:

Sub Main

Get FILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\prin.sav".
SORT CASES BY masterSiteID.
SAVE OUTFILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\prin2.sav"
/COMPRESSED.

Get FILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\teachers.sav".
SORT CASES BY masterSiteID.
SAVE OUTFILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\teachers2.sav"
/COMPRESSED.

MATCH FILES FILE="teachers2.sav" /TABLE="prin2.sav" /BY masterSiteID.
SAVE OUTFILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\match1.sav"
/COMPRESSED.



End Sub
When I ctrl +A hit play I get a dialogue box Missing command terminator. Ok to run?

Run it anyway and Get this

Get FILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\prin.sav".
SORT CASES BY masterSiteID.
SAVE OUTFILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\prin2.sav"
/COMPRESSED.

Get FILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\teachers.sav".
SORT CASES BY masterSiteID.
SAVE OUTFILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\teachers2.
sav"
/COMPRESSED.

MATCH FILES FILE="teachers2.sav" /TABLE="prin2.sav" /BY masterSiteID.
SAVE OUTFILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\match1.sav
"
/COMPRESSED.



End Sub

>Error # 1. Command name: End
>The first word in the line is not recognized as an SPSS command.
>This command not executed.

.
Get FILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\prin.sav".
SORT CASES BY masterSiteID.
SAVE OUTFILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\prin2.sav"
/COMPRESSED.

Get FILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\teachers.sav".
SORT CASES BY masterSiteID.
SAVE OUTFILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\teachers2.
sav"
/COMPRESSED.

MATCH FILES FILE="teachers2.sav" /TABLE="prin2.sav" /BY masterSiteID.
SAVE OUTFILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\match1.sav
"
/COMPRESSED.
GET
FILE='C:\Documents and Settings\Ted\Desktop\Dissertation Data\prin.sav'.


Please help
Analyst Techy
Moderator
Posts: 22
Joined: Mon Apr 27, 2009 2:19 am
Location: Melbourne, Australia

Re: Merging and matching

Postby Analyst Techy » Mon Jan 16, 2012 10:50 pm

Hi tkaniuka

.
Get FILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\prin.sav".
SORT CASES BY masterSiteID.
SAVE OUTFILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\prin2.sav"
/COMPRESSED.


/* Just remove the full stop (period) above the line GET FILE=
/* This should solve your problem.

/* If you are running a more recent version of SPSS e.g. Version 18+, you may also want to include the Syntax command DATASET CLOSE *. after every GET FILE e.g.

Get FILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\prin.sav".
DATASET CLOSE *.
SORT CASES BY masterSiteID.
SAVE OUTFILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\prin2.sav"
/COMPRESSED.

/* This is so SPSS does not lose focus with the Data Set that you are trying to manipulate.

/* GOOD LUCK
Analyst Techy

NOTES:
Any solutions I provide on this forum are free of charge, donations go towards the maintenance of the unaffiliated SPSS forum.
tkaniuka
Posts: 3
Joined: Sun Feb 27, 2011 9:52 pm

Re: Merging and matching

Postby tkaniuka » Sat Mar 31, 2012 7:14 pm

:?

Ok, ran this syntax a few months ago and it worked without fail now well it fails

Get FILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\prin.sav".
SORT CASES BY masterSiteID.
SAVE OUTFILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\prin1.sav"
/COMPRESSED.

Get FILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\teachers.sav".
SORT CASES BY masterSiteID.
SAVE OUTFILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\teachers1.
sav"
/COMPRESSED.

MATCH FILES FILE="teachers1.sav" /TABLE="prin1.sav" /BY masterSiteID.

>Error # 63 in column 18. Text: teachers1.sav
>The file does not exist.
>This command not executed.


>Error # 63 in column 41. Text: prin1.sav
>The file does not exist.


>Note # 5146
>There is no working file to restore. You must define a working file before
>proceeding with your analysis.

SAVE OUTFILE="C:\Documents and Settings\Ted\Desktop\Dissertation Data\match1.sav
"
/COMPRESSED.

EXECUTE.
But when go to the folder the folder has the two "missing" files. Help!!!!

Who is online

Users browsing this forum: No registered users and 2 guests

cron