Date: Wed, 16 Feb 2000 13:41:18 -0500
Reply-To: WHITLOI1 <WHITLOI1@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: WHITLOI1 <WHITLOI1@WESTAT.COM>
Subject: Re: SAS novice question
Content-Type: text/plain; charset=US-ASCII
Jeremy,
SAS is a record oriented language so processing variables on different records
at the same time usually means restructureing the data to produce the required
variables on one record.
The problem you posed has a simpler solution, because the records of interest
happen to be
adjacent. Take a look at the LAG and DIF functions.
On the other hand, learning how to manipulate data in arrays and restructure
data will prove more valuable in the long run.
Here is code to illustrate getting all data on one record where you have easy
access
data w ;
input id method var1 var2 var3 ;
cards ;
1 1 2 3 2
1 2 3 4 6
2 1 1 5 4
2 2 2 2 6
;
data t ( keep = id v1 - v6 ) ;
array v (2,3) ;
array var ( 3 ) ;
do until ( last.id ) ;
set w ;
by id ;
do i = 1 to dim ( var ) ;
v ( method , i ) = var ( i ) ;
end ;
end ;
run ;
data q ( keep = id diff1 - diff3 ) ;
set t ;
array diff ( 3 ) ;
array v (2,3) ;
do i = 1 to hbound ( v , 2 ) ;
diff ( i ) = v ( 2 , i ) - v ( 1 , i ) ;
end ;
run ;
Of course, steps two and three could be combined in one step. I left them
separate so that it would be easier to study them.
Ian Whitlock <whitloi1@westat.com
____________________Reply Separator____________________
Subject: SAS novice question
Author: H Jeremy Bockholt <jeremy-bockholt@UIOWA.EDU>
Date: 2/15/2000 12:06 PM
In SAS, is there a way to directly access a value of a variable when
there is more then one value?
example record
--------------------------------
id method var1 var 2 ... var10
1 1 2 3 2
1 2 3 4 6
2 1 1 5 4
2 2 2 2 6
-------------------------------
I have a method variable with 2 levels{1,2}, so each of my var1-var10
has 2 values for each id.
I want to be able to refer directly to var1 at a specific method level.
Let's say I want to calculate
diff=var1[method==1] - var[method==2]
Is there an easy way to do this?
thanks in advance for any advice,
jeremy
--
H Jeremy Bockholt
MH-CRC Neuroimaging Lab Database Analyst
2-126f MEB UI College of Medicine Iowa City IA work_phone: 335-8209
http://iowa-mhcrc.psychiatry.uiowa.edu/neuroimaging