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 Fri Sep 03, 2010 3:41 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: How do I compute a new variable that chooses earliest date2
PostPosted: Tue Mar 17, 2009 4:28 pm 
Offline

Joined: Tue Mar 17, 2009 4:20 pm
Posts: 1
I have a dataset with different dates for different persons, sorted in one column. I need to create a new variable that looks at the first data of a person and insert the earliest date into the new column. Do any of you know how I might do this? Thanks in advance.

Data is sorted like this:

DATA LIST LIST / person (F2.0) data (adate) .
BEGIN DATA
1 06/11/50
1 06/11/51
1 06/11/52
1 06/11/53
2 06/11/50
2 07/11/50
2 08/11/50
END DATA.


Top
 Profile  
 



 Post subject: Re: How do I compute a new variable that chooses earliest date2
PostPosted: Tue Mar 17, 2009 6:28 pm 
Offline
Moderator

Joined: Sun Dec 28, 2008 5:55 pm
Posts: 555
Location: Belo Horizonte, Brasil
It may not be the best syntax, but I couldn't get any smaller code...

First, compute a new variable that equals a future date. Then compute another variable usind the DATEDIFF function:
Code:
COMPUTE datedif=DATEDIFF(<future variable name here>,data,"days").


Now, the syntax will restructure the data in order to have a single case for each ID and extract the early date based on the difference computed before.
Code:
SORT CASES BY person.
CASESTOVARS
  /ID=person
  /GROUPBY=VARIABLE.

COMPUTE earlydate=max(datedif.1 to datedif.X).
EXECUTE.
IF (earlydate=datedif.1) Date=data.1.
IF (earlydate=datedif.2) Date=data.2.
IF (earlydate=datedif.3) Date=data.3.
IF (earlydate=datedif.4) Date=data.4.
IF (earlydate=datedif.X) Date=data.X.
EXCUTE.


The DATE variable is the earliest date. Just change the syntax according to the number of cases you have.

_________________
BR

NOTE: "Please read the Posting Guidelines and always tell us your OS, the SPSS version and some information about your data!" - by statman.

Disponível em português (mas prefira inglês para que outros também entendam a solução).


Top
 Profile  
 



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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


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:  
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.