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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

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