DATA Step, Macro, Functions and more

Add variable that identifies occurrence

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 145
Accepted Solution

Add variable that identifies occurrence

[ Edited ]

Hi Everyone,

 

Can some one help me with query. I have dataset with three variables ID,DATE ANDTIME....ID is identifier,date is date of collection and time of collection of sample....for every ID and Same Date:I would like to create new variable timepoint such a way that first occuarance will be assigned 'PRE' ,second occurance will be '2H' and third occurance will be '7H'...

 

100020005 2015-08-27 08:36
100020005 2015-08-27 11:32
100020005 2015-08-27 14:51
100020008 2015-10-01 08:23
100020008 2015-10-01 10:56
100020008 2015-10-01 15:32

140020004 2014-12-18 13:13

140020002 2014-09-30 14:45
140020002 2014-09-30 17:20

 

The output should look like this with new 4th variable time point....

 

100020005 2015-08-27 08:36  PRE
100020005 2015-08-27 11:32  2H
100020005 2015-08-27 14:51  7H
100020008 2015-10-01 08:23  PRE
100020008 2015-10-01 10:56  2H
100020008 2015-10-01 15:32  7H

140020004 2014-12-18 13:13  PRE

140020002 2014-09-30 14:45  PRE
140020002 2014-09-30 17:20  2H

 

Thanks in advance

Rakesh

 


Accepted Solutions
Solution
‎02-24-2016 04:17 PM
Super Contributor
Posts: 490

Re: Add variable that identifies occurrence

[ Edited ]
data have;
input id date yymmdd10. time TIME.;
format time time.;
cards;
100020005 2015-08-27 08:36
100020005 2015-08-27 11:32
100020005 2015-08-27 14:51
100020008 2015-10-01 08:23
100020008 2015-10-01 10:56
100020008 2015-10-01 15:32
140020004 2014-12-18 13:13
140020002 2014-09-30 14:45
140020002 2014-09-30 17:20
;
run;
proc sort data=have;
by id date time;
run;
data want;
set have;
retain f;
by id date time;
if first.date then f=1;
if f=1 then point='PRE';
else if f=2 then point= '2H';
else if f=3 then point='7H';
f+1;
drop f;
run;

View solution in original post


All Replies
Solution
‎02-24-2016 04:17 PM
Super Contributor
Posts: 490

Re: Add variable that identifies occurrence

[ Edited ]
data have;
input id date yymmdd10. time TIME.;
format time time.;
cards;
100020005 2015-08-27 08:36
100020005 2015-08-27 11:32
100020005 2015-08-27 14:51
100020008 2015-10-01 08:23
100020008 2015-10-01 10:56
100020008 2015-10-01 15:32
140020004 2014-12-18 13:13
140020002 2014-09-30 14:45
140020002 2014-09-30 17:20
;
run;
proc sort data=have;
by id date time;
run;
data want;
set have;
retain f;
by id date time;
if first.date then f=1;
if f=1 then point='PRE';
else if f=2 then point= '2H';
else if f=3 then point='7H';
f+1;
drop f;
run;
Super User
Super User
Posts: 7,430

Re: Add variable that identifies occurrence

What is your reference point?  Without a reference point there is no way you can state that 8:36 is pre anything?  As you are talking about samples I will assume your dealing with pharma study data, in which case PRE would refer to dosing time.  Therefore the first task to undertake here is to merge dosing time onto your sample data, based on subject period visit.  Then compare the time of sample to the time of dosing.  if it is < dosing time you know it is pre, other wise you take the time of dosing away from the sample time and then assign based on nearest planned time window, so 2h or 7h.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 181 views
  • 1 like
  • 3 in conversation