Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Copying a variable from one dataset to another in SPSS

9,655 views
Skip to first unread message

lne...@gmail.com

unread,
Jan 12, 2009, 10:10:55 AM1/12/09
to
Hi

Does anybody know how I copy a variable from one dataset to another
dataset in SPSS? The copy-paste method only results in an empty
variable.

Thanks!

martijnv...@gmail.com

unread,
Jan 12, 2009, 3:32:09 PM1/12/09
to

You can copy-paste the variable definition (datatype, length, ect) in
the variable view. After that you can paste the data in the variable
view. When doing the paste of the data, make sure you select at least
as many cells as you are going to paste. SPSS is not like Excel where
you can paste into one cell and it writes the data to the cells below
as needed. You need to select every cell into which you want to paste
data.

Bruce Weaver

unread,
Jan 12, 2009, 3:39:07 PM1/12/09
to


It seems to me that merging files (MATCH FILES) might be easier. If a
tutorial is needed, click on the Data Management link at the site
given below, then look for "Merging (MATCH merging) SPSS data files".

http://www.ats.ucla.edu/stat/spss/

--
Bruce Weaver
bwe...@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/
"When all else fails, RTFM."

martijnv...@gmail.com

unread,
Jan 12, 2009, 3:51:58 PM1/12/09
to
> bwea...@lakeheadu.cahttp://sites.google.com/a/lakeheadu.ca/bweaver/

> "When all else fails, RTFM."

Good catch Bruce, match files is definitely more user-friendly and
less error-prone. There are some things to be aware of when you're
matching files to add variables: when you merge, you need a variable
that exists in both datasets, and uniquely identifies each case in
both datasets. The merging variable must be of the same type AND
length in both datasets, and you have to make sure that both datasets
are sorted ascending on the matching variable.

RichUlrich

unread,
Jan 13, 2009, 12:10:28 AM1/13/09
to
On Mon, 12 Jan 2009 12:51:58 -0800 (PST), martijnv...@gmail.com
wrote:

Or, it is *possible* to match to files without any ID variable
in the syntax. (At least, it used to be.) (Jon - Perhaps this
behavior ought to be available *only* when invoked by a
special keyword?)

If you give it no ID variable, SPSS will assume that the lines
belong together, one by one, in the order that they exist
respectively in the two files.
- This should never be used if you can avoid it. Unsafe.
- You should be *aware* of it, to avoid omitting your ID variables.
You certainly don't want this outcome by accident.


--
Rich Ulrich

martijnv...@gmail.com

unread,
Jan 13, 2009, 3:37:09 AM1/13/09
to
On 13 jan, 06:10, RichUlrich <rich.ulr...@comcast.net> wrote:
> On Mon, 12 Jan 2009 12:51:58 -0800 (PST), martijnvanderw...@gmail.com

Hi Rich,

if this was possible before, maybe it still is. I did not know that
this used to be possible.

Bruce Weaver

unread,
Jan 13, 2009, 9:22:26 AM1/13/09
to
On Jan 13, 12:10 am, RichUlrich <rich.ulr...@comcast.net> wrote:

>
> Or, it is *possible*  to match to files without any ID variable
> in the syntax.   (At least, it used to be.)   (Jon - Perhaps this
> behavior ought to be available *only*  when invoked by a
> special keyword?)
>
> If you give it no ID variable, SPSS will assume that the lines
> belong together, one by one, in the order that they exist
> respectively in the two files.
>  - This should never be used if you can avoid it.  Unsafe.
>  - You should be *aware*  of it, to avoid omitting your ID variables.
> You certainly don't want this outcome by accident.

Yes, one can still match with no use of BY. But as Rich notes, it can
be dangerous. Here's an example.

* --- Start of example --- .

data list list / id x1 (2f5.0).
begin data
1 5
2 4
3 4
4 2
5 4
end data.
dataset name dataset1 .

data list list / id x2 (2f5.0).
begin data
1 3
3 5
4 3
5 5
end data.
dataset name dataset2 .

* MATCH FILES without BY .

match files
file = 'dataset1' /
file = 'dataset2' .
exe.
list.

* MATCH FILES with BY .

match files
file = 'dataset1' /
file = 'dataset2' /
BY ID .
exe.
list.

* --- End of example --- .

Notice that ID number 2 is missing from the second data set. Here is
the output.

From the first MATCH FILES (without BY):

id x1 x2
1 5 3
2 4 5 <-- Incorrect matching from here down
3 4 3
4 2 5
5 4 .

From the second MATCH FILES (with BY):

id x1 x2
1 5 3
2 4 . <-- Correct!
3 4 5
4 2 3
5 4 5

--
Bruce Weaver
bwe...@lakeheadu.ca

JKPeck

unread,
Jan 13, 2009, 9:28:21 AM1/13/09
to

Yes, you can match without an explicit id variable. Obviously this is
risky except under controlled conditions so having an id variable is
certainly recommended. AFAIK, this has been possible for over 25
years.

-Jon

Message has been deleted

prof.f...@gmail.com

unread,
Dec 15, 2017, 3:55:38 PM12/15/17
to
See Star Join in manual of syntax

prof.f...@gmail.com

unread,
Dec 15, 2017, 3:56:41 PM12/15/17
to
See Star Join in the docs syntax
0 new messages