computing new var searching across multiple vars

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

nina.vandyke
Posts: 3
Joined: Thu Jan 05, 2012 4:53 am

computing new var searching across multiple vars

Postby nina.vandyke » Thu Jan 05, 2012 5:36 am

Hi, My dataset includes dates and scores for a health assessment. The dates are SPSS dates. The scores are numeric. Some clients have taken no assessments, some have taken one, and some have taken more than one (the most is 19 times). The data looks something like this:

Client Score1 Date1 Score2 Date2... Score19 Date19

The dates are not necessarily in order. In other words, Date2 might be earlier than Date1. What I would like to do is create four new variables: ScoreFirst, DateFirst, ScoreLast, DateLast, where ScoreFirst and DateFirst are the earliest date and corresponding score, and ScoreLast and DateLast are the most recent date and corresponding score. I understand how to find DateFirst and Datelast: Use Transform -> Compute MIN, MAX. But how do I get the associated score? For example, if, for a particular client, the earliest date is Date4, then I would want the value of Score4 for ScoreFirst.

I am using PASW Statistics 18.

Thanks!
Stelios
Posts: 2
Joined: Fri Oct 16, 2009 7:45 am

Re: computing new var searching across multiple vars

Postby Stelios » Thu Jan 05, 2012 8:07 am

Hello,

Check this syntax code. I think this will solve your problem.
To use this code you must first change the order of your variables and make it:
Client date1 ... date19 score1 ... score19

VECTOR VC1 = date1 TO date19.
VECTOR VC2 = score1 TO score19.

LOOP #I=1 TO 19.
DO IF (VC1(#I) = min(date1 to date19)).
COMP datefirst=VC1(#I).
COMP scorefrst=VC2(#I).
END IF.
DO IF (VC1(#I) = max(date1 to date19)).
COMP datelast=VC1(#I).
COMP scorelast=VC2(#I).
END IF.
END LOOP.
EXE.
nina.vandyke
Posts: 3
Joined: Thu Jan 05, 2012 4:53 am

Re: computing new var searching across multiple vars

Postby nina.vandyke » Thu Jan 05, 2012 11:53 pm

Hi Stelios, This is great --thanks. Much better than my fallback, which was a series of If-Then statements.
Just one thing, though -- it works great if there are at least two scores, but if there is only one score, I need scorelast to be missing.

Thanks, Nina
nina.vandyke
Posts: 3
Joined: Thu Jan 05, 2012 4:53 am

Re: computing new var searching across multiple vars

Postby nina.vandyke » Tue Jan 10, 2012 6:02 am

Hi, Just wanted to let you know I answered my own question. I just added this line of code:

IF (datefirst = datelast) scorelast=$SYSMIS.
EXECUTE.

Cheers,
Nina

Who is online

Users browsing this forum: No registered users and 2 guests

cron