BookmarkSubscribeRSS Feed
samhuang
Calcite | Level 5
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
1 REPLY 1
deleted_user
Not applicable
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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 1 reply
  • 1247 views
  • 0 likes
  • 2 in conversation