spssforum.com from users, for users

SPSSforum.com is the largest free SPSS help resource worldwide.
On this SPSS forum you are sure to get an answer to your question!
Join the forum and let other SPSS users help you.

Join the SPSS users Group on LinkedIn
Join the SPSS Users Group
on LinkedIn
 
SPSSforum.com is a forum for SPSS users. Ask any question you like about SPSS or statistics.

It is currently Thu Sep 09, 2010 4:37 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Syntax to create new dataset with subset of variables
PostPosted: Fri Mar 05, 2010 2:01 am 
Offline

Joined: Fri Mar 05, 2010 1:56 am
Posts: 2
A few times recently I've wanted to create a new dataset using only a subset of the variables out of a very large one. Rather than going through and copying and pasting the variables I want, is there syntax to do this? I'm familiar with the 'write outfile' command, but this doesn't seem to save the important variable information, like type of data, value labels, etc.

Seems like this should be easy. Any help?


Top
 Profile  
 



 Post subject: Re: Syntax to create new dataset with subset of variables
PostPosted: Fri Mar 05, 2010 5:46 am 
Offline
Moderator

Joined: Mon Apr 27, 2009 2:19 am
Posts: 278
Location: Melbourne, Australia, University
Hi plr2

You could try the SPSS base menu options Data>Select Cases>Var1=1>Select output-copy selected cases to a new dataset.

A simple syntax equivalent would be DATASET COPY Subset1.
DATASET ACTIVATE Subset1.
FILTER OFF.
USE ALL.
SELECT IF (V1 = 1).
EXECUTE.

==================================

More complex syntax is below


In SPSS>File>New>Syntax and copy the syntax below.

Adapt code to your own variable names.

1. The key changes are to "grpvar" and change values 1 2 3 e.g. to !SplitDataSets 11 12 13/.
2. The key name changes are to "XVar" and "YVar".


/* Created by Analyst Techy 03 Mar 2010

/* 1. Divide the dataset into smaller datasets

/* Splits a dataset up by a grouping variable e.g. grpvar
/* for this syntax to work you have to have a numeric variable named grpvar
/* The grp values are 1, 2,3 within the variable grpvar
/* Assuming a recent version of SPSS
/* Open SPSS sav file before running



DEFINE !SplitDataSets (!POS !CHAREND ('/'))

!DO !gv !IN (!1)

!LET !SepSets = !CONCAT('SepDataSet',!gv)

DATASET COPY !SepSets.
DATASET ACTIVATE !SepSets.
FILTER OFF.
USE ALL.
SELECT IF (grpvar = !gv).
EXECUTE.

!DOEND

!ENDDEFINE.

!SplitDataSets 1 2 3/.

=============================

Even more advanced...

You could adapt the code above and get the PC working for you, but you'd have to use VBA script and set up a cursor to traverse the SPSS dataset. If you are familiar with PL/SQL you probably no what I'm talking about. Please email me for tips on doing this in SPSS.

_________________
Analyst Techy

NOTES:
1. It is not ethical for me to provide complete answers to assignment/work solutions.
2. Any solutions I provide on this forum are free of charge, donations go towards the maintenance of the unaffiliated SPSS forum.


Top
 Profile  
 
 Post subject: Re: Syntax to create new dataset with subset of variables
PostPosted: Fri Mar 05, 2010 6:14 pm 
Offline

Joined: Fri Mar 05, 2010 1:56 am
Posts: 2
I'm confused--I don't want to copy some of the cases. I want ALL of the cases. I only want a few of the variables. I want to modify syntax like this:

write outfile= 'K:\NURIUS_R01\RIFP_RRF_papers\PR_MAPSvars.sav'
/id maps1 m1d m1a m1h m1anwoperp m1nstres m1stress (etc).
exe.

But I want a .sav with all of the variable information included for all of the cases. Doesn't seem like the syntax you've provided will do that. Am I missing something?


Top
 Profile  
 
 Post subject: Re: Syntax to create new dataset with subset of variables
PostPosted: Fri Mar 19, 2010 4:58 am 
Offline
Moderator

Joined: Mon Apr 27, 2009 2:19 am
Posts: 278
Location: Melbourne, Australia, University
Hi

Sorry about the delay in getting back to you.

I don't think WRITE OUTFILE is appropriate for what you want to achieve, I use WRITE OUTFILE for creating libraries for macros.
I'd use SAVE OUTFILE instead.

/* In your syntax use-make sure you have the full stop at the end of the code.
SAVE OUTFILE='dito.sav'
/KEEP=id maps etc.

_________________
Analyst Techy

NOTES:
1. It is not ethical for me to provide complete answers to assignment/work solutions.
2. Any solutions I provide on this forum are free of charge, donations go towards the maintenance of the unaffiliated SPSS forum.


Top
 Profile  
 



Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Template made by DEVPPL

This site is in no way connected with SPSS Inc. or any affiliate of SPPS Inc. The SPSS logo and products are owned by and copyrighted by SPSS Inc. The views expressed in the messages posted on this site are those of persons writing those comments and not necessarily those of the SPSSforum.com. SPSSforum.com does not vouch for the accuracy or truthfulness of any posted statement or opinion. The SPSSforum.com has, however, refrained from posting any item containing any statement known to be inaccurate, false or baseless.