Thursday 4 January 2007

Getting data into SPSS

Several ways of introducing data to SPSS!

1. Type data by yourself and die!
2. Open data file (*.sav) and be happy!
3. Import data from Excel file (*.xls).
4. Import data from Database (via ODBC, etc.).

In the last case, Syntax should look like this:
[Syntax]
GET DATA
/TYPE=ODBC
/CONNECT='DNS=MS Access Database;DBQ=C:\demo.mdb;'+'DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;'
/SQL =
'SELECT Age, Education, Income'
'FROM GeneralInfosTable'
'WHERE ([Marital Status] <> 2 AND MobilePhone = 1)'.
EXECUTE.
[Syntax]
As we can see that we import data from Microsoft Access Database under certain conditions.

If you want to do the Excel way, you might consider this:
[Syntax]
GET DATA
/TYPE=XLS
/FILE='c:\demo.xls'
/SHEET=NAME 'Income'
/CELLRANGE= RANGE 'A1:K23'
/READNAMES=on.
EXECUTE.
[Syntax]

And if you want to read from a text (*.txt) file use:
[Syntax]
DATA LIST FREE
FILE ='c:\delimited_numbers.txt'
/id (f4) sex (a1) age (F2) opinion1 to opinion5 (5F).
EXECUTE.
[/Syntax]

Or you can - god noooo - type in all the data (directly to your SPSS Data View or you can use smth. like this):
[Syntax]
DATA LIST FREE
/var1(f2) var2(f2) var3(f2) var4(f3) var5(f2) name(a10).
BEGIN DATA
12 22 31 42 51 john
22 23 42 44 21 marry
55 53 32 11 12 fred
END DATA.
EXECUTE.

[/Syntax]

10 comments:

Anonymous said...

fair enough SPSS lovers..
Back to the syntax; I am hoping someone can anwser this question.
When using a SQL statement via odbc is it possible to make a complex query? My definition of complex would be the use of statement like 'group by', 'distinct' ' etc. or the use of correlated sub-queries (example: SELECT p.product_name FROM product p
WHERE p.product_id = (SELECT o.product_id FROM order_items o
WHERE o.product_id = p.product_id); )
What are SQL the commands that are supported?

Simon said...

WARNING: using this command in any version of SPSS under Windows Vista may cause records to be duplicated or dropped at random.

Anonymous said...

I am trying to write a syntax for this data (nested data) could you help please rcmoulirc@gmail.com
1 13n24
2 1EKK654 2
3121 111
3232 112
32 6 112
1 31y41
2 3ICT757 1
3218 221
3117 222
2 2JUZZI 2
3129 111
3127 212
2 2QYT658 4
3241 221
1 22y21
2 5JUY612 1
3132 111
2 3MHG427 1
3264 111
1 22n22
2 1RT4321 2
3154 111
3113 112
3253 112
3211 112
2 4PEW923 3
3219 111
3219 112
1 13y14
2 9FDE999 2
3121 221
1 15n12
2 1FRE487 2
3265 111
3164 112
3264 112
3159 112

Mouli said...

Can somebody help me in creating a syntax for this example?
pls mail me at rcmoulirc@gmail.com
This school.txt data file gives details about staff members at a particular school.

The variables in the file are

For all staff
GENDER
AGE
MARITAL marital status
POSITION Position in School (1=head of dept. 2=teacher 3=admin)
SALARY Salary level

For heads of department
NOSTAFF Number of staff in department
NCONTACT Number of contact periods
BUDGET Dept. budget

For teachers
SUBJECT main subject area
CONTACT no. of contact periods
PUPILS no. of pupils taught this year

For administration staff
HOURS no.of hours worked
QUAL qualification

The column locations of the variables are as follows:
Variable Rec Start End Format
GENDER 1 1 1 A1
AGE 1 2 3 F2.0
MARITAL 1 4 4 F1.0
POSITION 1 5 5 F1.0
SALARY 1 6 6 F1.0
NOSTAFF 1 7 8 F2.0
NCONTACT 1 9 10 F2.0
BUDGET 1 11 17 Dollar
SUBJECT 1 7 8 F2.0
CONTACT 1 9 10 F2.0
PUPILS 1 11 14 F4.0
HOURS 1 7 10 F4.0
QUAL 1 11 11 F1.0

A sample of data is shown
M43112 228$2000.0
M36212 526$4000.0
M453121215$2000.0
M24123 130 66
F54123 130 80
F28223 130 112
F54135 401
F43135 382
F42135 291

Rhydhun said...

Could someone please help me with the following 2 issues. Any direction will be greatly appreciated -

(1) let me know of the syntax that would help me copy selected variables (and their corresponding data) from one SPSS file to another?

(2) How do I copy the variable labels from one set of variables into another without needing to run the data dictionary command each time? Is there a syntax I can use?

Rhydhun said...

Another quick question -
For one of my projects I need to create a variable sized vector. That is, I need to be able to say something similar to -

Vector xx (count).

But SPSS takes in a positive integer alone. Is there any way to work around it?

Anonymous said...

Gorge yourself on style with the fashionably edgy junk food E/W shoulder designers outlet Hardy clothing
. Go for the studded detail ED Hardy Shoes
. The ED Hardy Shoes
is put at the high front. The interior is printed all over with hardy shirt
logos and offers zip pocket and two open pockets.

Anonymous said...

Gorge yourself on style with the fashionably edgy junk food E/W shoulder designers outlet Hardy clothing
. Go for the studded detail ED Hardy Shoes
. The ED Hardy Shoes
is put at the high front. The interior is printed all over with hardy shirt
logos and offers zip pocket and two open pockets.

true religion jeans said...

There is nothing easier than studying from home to get there and change your career forever.
In our service you can find some useful.

Unknown said...
This comment has been removed by the author.