Calculating reaction time in the dataset by using SAS

Reply
New Contributor
Posts: 2

Calculating reaction time in the dataset by using SAS

Hi

I would like calculate the reaction time in the dataset by using SAS (and then do the following statistics). My data looked like this:

Subj: 1
N Time Trigger_number
1 0 0
2 1.3 100
3 4.6 1
4 5 0
5 6 200
6 9.4 1
7 12 0
8 15 0
9 18.4 1
10 20 0

The trigger_number "100" and "200" refer to the correct stimuli, and the trigger_number "1" refers to response. I only want to calculate the correct response (that is, ignore the false positive events like event 9), and the desired RT should fulfill the following conditions:
1. trigger_number=1 but only if the precedent trigger_number is either 100 or 200.
2. calculate the reaction time by subtract the "time" of the event that the trigger_number is 100 or 200 from the "time" of the event that the trigger_number is 16.

How can I code this in SAS?

Really appreciate for your kindly help!!!!

Samantha
N/A
Posts: 0

Re: Calculating reaction time in the dataset by using SAS

There are a few ways you can do this. Since there are different subjects you want to take care not to carry over any values from the previous subject. The general idea is to create two temporary variables and RETAIN their values from one iteration of the data step to the next. One is for TIME and the other for TRIGGER_NUMBER. When captured this way the values from the previous observation become available for processing until they are changed in the current observation by an assignment statement. Now, you are all set to compare the values of these two variables from the current observation with the previous observation. This is presented below. Please note that I have added SUBJ.

data oldtrigger ;
input subj N Time Trigger_number ;
cards ;
1 1 0 0
1 2 1.3 100
1 3 4.6 1
1 4 5 0
1 5 6 200
1 6 9.4 1
1 7 12 0
1 8 15 0
1 9 18.4 1
1 10 20 0
run ;

data newtrigger ;
set oldtrigger ;
by subj ;
retain lasttrig lasttime ;
if first.subj then
do ;
lasttrig = . ;
lasttime = . ;
end ;
else if trigger_number = 1 and
lasttrig in (100,200) then
do ;
reacttime = time - lasttime ;
end ;
lasttime = time ;
lasttrig = trigger_number ;
drop last: ;
run ;

There is at least one other method to do the same (hint: LAG function). There are also some other ways but that would require an advanced understanding of the data step to supplant its default iteration with your own.

Venky Chakravarthy
Ask a Question
Discussion stats
  • 1 reply
  • 298 views
  • 0 likes
  • 2 in conversation