Hello All,
I've got program start dates for individuals and need to match their corresponding assessments according to whether the assessment was done during certain time frames - start date to start date + 180 days, start date + 181 days to start date + 360 days, etc. My real data has 4 time periods where assessment scores need to be placed. What I would like to do is to use an IF statement to push through two transformations instead of one. If the assessment date was between the start date in the program and 180 day after the program start, I would like: 1) AssessDate180=assessdate.1 AND 2) AssessScore180=assessscore.1 In otherwords, is there a way to combine the last two IF statements into one statement? Thanks, Ariel Please see the data below. DATA LIST LIST /client_no (F8) startdate (ADATE10) startdate180 (ADATE10) assessdate.1 (ADATE10) assessscore.1 (F8.0). BEGIN DATA 3442 7/8/2009 1/4/2010 8/12/2009 65 1217 12/19/2009 6/17/2010 7/3/2010 78 5916 1/5/2009 7/4/2009 1/8/2009 92 END DATA. COMPUTE AssessDate180=0. COMPUTE AssessScore180=0. RECODE AssessDate180 AssessScore180 (0=SYSMIS). EXECUTE. FORMATS AssessDate180 (ADATE10). IF (assessdate.1>=startdate) AND (assessdate.1<startdate180) AssessDate180=assessdate.1. IF (assessdate.1>=startdate) AND (assessdate.1<startdate180) AssessScore180=assessscore.1. EXECUTE. |
Hi Ariel, Yes, there is: the do if
... end if-construct. DO IF (assessdate.1>=startdate) AND
(assessdate.1<startdate180). compute AssessDate180=assessdate.1. compute AssessScore180=assessscore.1. END IF.
Kind regards, Gerard van Meurs Van: SPSSX(r)
Discussion [mailto:[hidden email]] Namens
Ariel Barak Hello All, |
In reply to this post by ariel barak
Ariel,
No. You are applying the same test to two different variables.
Two lines of code is as short as you can get.
If you were willing to write three lines of code you could use
a Do repeat structure like this
do repeat y=AssessDate180 AssessScore180/x=assessdate.1
assessscore.1.
if (assessdate.1>=startdate) AND
(assessdate.1<startdate180) compute x=y.
end repeat. Gene
Maguin
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Ariel Barak Sent: Friday, May 20, 2011 10:19 AM To: [hidden email] Subject: 2 Transformations with 1 IF statement? I've got program start dates for individuals and need to match their corresponding assessments according to whether the assessment was done during certain time frames - start date to start date + 180 days, start date + 181 days to start date + 360 days, etc. My real data has 4 time periods where assessment scores need to be placed. What I would like to do is to use an IF statement to push through two transformations instead of one. If the assessment date was between the start date in the program and 180 day after the program start, I would like: 1) AssessDate180=assessdate.1 AND 2) AssessScore180=assessscore.1 In otherwords, is there a way to combine the last two IF statements into one statement? Thanks, Ariel Please see the data below. DATA LIST LIST /client_no (F8) startdate (ADATE10) startdate180 (ADATE10) assessdate.1 (ADATE10) assessscore.1 (F8.0). BEGIN DATA 3442 7/8/2009 1/4/2010 8/12/2009 65 1217 12/19/2009 6/17/2010 7/3/2010 78 5916 1/5/2009 7/4/2009 1/8/2009 92 END DATA. COMPUTE AssessDate180=0. COMPUTE AssessScore180=0. RECODE AssessDate180 AssessScore180 (0=SYSMIS). EXECUTE. FORMATS AssessDate180 (ADATE10). IF (assessdate.1>=startdate) AND (assessdate.1<startdate180) AssessDate180=assessdate.1. IF (assessdate.1>=startdate) AND (assessdate.1<startdate180) AssessScore180=assessscore.1. EXECUTE. |
In reply to this post by ariel barak
At 10:19 AM 5/20/2011, Ariel Barak wrote:
>If the assessment date was between the start date in the program and >180 day after the program start, I would like: > >1) AssessDate180=assessdate.1 AND >2) AssessScore180=assessscore.1 > >In otherwords, is there a way to combine the last two IF statements >into one statement? >... >IF (assessdate.1>=startdate) AND (assessdate.1<startdate180) > AssessDate180=assessdate.1. >IF (assessdate.1>=startdate) AND (assessdate.1<startdate180) > AssessScore180=assessscore.1. Of the two solutions posted, the DO IF will be the faster, possibly by enough to matter, since it tests the date value only once, not twice. (There've been several postings about slow code that appeared to be caused by its containing a great many IF tests.) It sounds like your actual code will have tests for not just 1-180 days, but a set of intervals. A reasonably fast and readable version might look like this: COMPUTE DaysSinceStart = CTIME.DAYS(assessdate.-startdate). DO IF RANGE(DaysSinceStart, 1,180). . COMPUTE AssessDate180=assessdate.1 . COMPUTE AssessScore180=assessscore.1. ELSE IF RANGE(DaysSinceStart,181,360). . COMPUTE AssessDate360=assessdate.1. . COMPUTE AssessScore360=assessscore.1. ELSE IF RANGE(DaysSinceStart,361,540). ... END IF. Or, you could very fast but, perhaps, less readable code, by making the AssessDatexxx and AssessScorexxx variables elements of two vectors, and writing something like this (untested): COMPUTE DaysSinceStart = CTIME.DAYS(assessdate.-startdate). COMPUTE #Interval = TRUNC(DaysSinceStart)/180. COMPUTE COMPUTE AssessDate(#Interval) =assessdate.1 COMPUTE AssessScore(#Interval)=assessscore.1. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Thanks everyone. I think the DO IF RANGE approach is the way to go.
Thanks again, Ariel On Tue, May 24, 2011 at 3:33 PM, Richard Ristow <[hidden email]> wrote:
|
Free forum by Nabble | Edit this page |