Date: Mon, 12 Aug 1996 12:01:42 EDT whitloi1@WESTATPO.WESTAT.COM "SAS(r) Discussion" Ian Whitlock Re: Data format problem To: Trish Forrest

Subject: Data format problem Summary: SQL can simplify the code to calculate quarters. Respondent: Ian Whitlock <whitloi1@westat.com>

Trish Forrest <trish@BITSY.CCS.QUEENSU.CA> asks how to calculate means for (SUBJ?), COND, FREQ, BLOCK, QUARTER where QUARTER is not on the file but a variable OBS indicating the sequential time of each observation is. In her words:

>>>>>>>>>>>>>>>>>> Each subject's data file consists of a series of trials (from an experiment) in which force readings were taken every 100 msec in a variety of conditions. The problem is that each trial is a different length (ie some have 200 lines of data, some have 320 etc). What I ultimately want to do is to get an average & standard deviation of the force for the first quarter, second quarter, third quarter & last quarter of each trial. Once I see the data, I may then revise this into thirds etc. Each subject performed the experiment under a variety of conditions & I want the means for each quarter in each of these conditions for each subject. So, the data file looks something like this:

subj cond freq block force obs 1 1 20 1 2.3 100 1 1 20 1 3.2 200 .. .. .. Within each condition (1 or 2) each subject received 5 different frequencies, and within each frequency there were 2 blocks.

So, in simple terms the program has to do a proc means for the force variable by cond, freq block (but the means are on each quarter). <<<<<<<<<<<<<<<<<<

PROC SQL can help simplify the calculation of quarter. Here is the code.

proc sql ; create table w2 as select subj , cond , force , freq , block , obs , max ( obs ) as maxobs , case when ( obs > (3/4) * calculated maxobs ) then 3 when ( obs > (2/4) * calculated maxobs ) then 2 when ( obs > (1/4) * calculated maxobs ) then 1 else 0 end as qtr from w group by subj , cond , freq , block ; quit ;

proc means data = w2 mean ; class subj cond freq block qtr ; var force ; run ;

For test data I used

data w ( keep = subj cond obs force freq block ) ; do subj = 1 to 3 ; nobs = ceil ( ranuni ( 123456789 ) * 30 ) ; do obs = 100 to nobs * 100 by 100 ; do cond = 1 to 2 ; do freq = 20 , 40 , 60 , 80 , 100 ; do block = 1 , 2 ; force = ranuni ( 123456789 ) ; output ; end ; end ; end ; end ; end ; run ;

Ian Whitlock

Back to: Top of message | Previous page | Main SAS-L page