Add variables

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

JolienK
Posts: 9
Joined: Tue Jul 14, 2015 5:34 pm

Add variables

Postby JolienK » Thu Jul 23, 2015 2:29 pm

I'm trying to add a variable from another dataset, how do you do that the easy way? Because the both datasets contain a lot variables, but I just need to add 1. Now I'm doing merge files and then add variables. But now I have to select my whole dataset and that's pretty big. (look at attached image). Is there a faster/easier way? Because I need to do this with three other datasets, and this way it's gonna take a while.

Thanks a lot (again) ;)
You do not have the required permissions to view the files attached to this post.
RubenGeert
Posts: 100
Joined: Mon May 19, 2014 6:06 am

Re: Add variables

Postby RubenGeert » Thu Jul 23, 2015 2:53 pm

Use MATCH FILES for doing so: http://www.spss-tutorials.com/spss-match-files-command/

Even if you're not really used to working from syntax, this one is very simple. After trying the examples from the tutorial, you'll probably merge a variable into your actual data with full confidence!
JolienK
Posts: 9
Joined: Tue Jul 14, 2015 5:34 pm

Re: Add variables

Postby JolienK » Thu Jul 23, 2015 3:08 pm

I'm still a bit confused. The thing is, I want to keep all the variables from my active dataset and from the other I only need 1 variable, all the other variables should be dropped here. Which syntax should I use?

Thanks!
RubenGeert
Posts: 100
Joined: Mon May 19, 2014 6:06 am

Re: Add variables

Postby RubenGeert » Thu Jul 23, 2015 3:45 pm

Add a KEEP subcommand as in

match files file = dataset1 / file = dataset2
/by id
/keep oldvar_a TO oldvar_z newvar_a.

where oldvar_a TO oldvar_z are the first and last variables in you main data and newvar_a is the one variable you're merging into the main data.
JolienK
Posts: 9
Joined: Tue Jul 14, 2015 5:34 pm

Re: Add variables

Postby JolienK » Thu Jul 23, 2015 3:56 pm

It doesn't work... I get this error:
>Error # 5241 in column 5. Text: id
>Undefined variable name. Check spelling, verify the existence of this
>variable. Has it been dropped or renamed in this command?
>Execution of this command stops.

What am I doing wrong?
RubenGeert
Posts: 100
Joined: Mon May 19, 2014 6:06 am

Re: Add variables

Postby RubenGeert » Thu Jul 23, 2015 4:19 pm

The syntax is just an example. "id" refers to the variable which identifies which case from one dataset corresponds to which case in the other dataset. In a similar vein, "dataset1" and "dataset2" probably have different names for your data as well.

Who is online

Users browsing this forum: No registered users and 1 guest

cron