adding variable values in increments

Reply
New Contributor
Posts: 3

adding variable values in increments

Hi all, 

I am working on a dosing project where I need to add the concentration at time 12 to the concentration at time 0, concentration at time 12.25 to concentration at .25, concentration at 12.5 to the concentration at .5 .. etc. etc. etc. 

 

The following is code that I have come up with so far.. 

 

data test2;
set test;
if time >= 12 then do;
conc2=conc+5;      /*i need to add the concentration from 12 hours prior to the current concentration, '5' is my placeholder*/
end;                       /*i.e. conc2 at hour 13 = current concentration at hour 13 + concentration at hour 1*/
else conc2=conc;    /*all concentrations prior to hour 12 are to remain the same*/
run;

 

this may be an easy fix, but I've been looking at it so long i'm going cross eyed

any help would be appreciated, thanks in advance

Regular Contributor
Posts: 152

Re: adding variable values in increments

data test;

set ....;

if time ge 12 then do;

timept=2;

newt=time-12;

end;

else do;

timept=1;

newt=time;

end;

run;

 

proc sort data=test;

by newt;

run;

 

proc transpose data=test out=test_t prefix=time;

var conc;

id timept;

by newt;

run;

 

data test2;

set test_t;

x=time1+tim2;

run;

 

something like this maybe

--------------
blog: papersandprograms.com
New Contributor
Posts: 3

Re: adding variable values in increments

Posted in reply to PaulBrownPhD
playing with this to see if it can work..
I'm keen on the thought of making a new variable, but I think the 'transpose' step is not working how I need it to..
Super User
Posts: 13,498

Re: adding variable values in increments


@klinz wrote:

Hi all, 

I am working on a dosing project where I need to add the concentration at time 12 to the concentration at time 0, concentration at time 12.25 to concentration at .25, concentration at 12.5 to the concentration at .5 .. etc. etc. etc. 

 

The following is code that I have come up with so far.. 

 

data test2;
set test;
if time >= 12 then do;
conc2=conc+5;      /*i need to add the concentration from 12 hours prior to the current concentration, '5' is my placeholder*/
end;                       /*i.e. conc2 at hour 13 = current concentration at hour 13 + concentration at hour 1*/
else conc2=conc;    /*all concentrations prior to hour 12 are to remain the same*/
run;

 

this may be an easy fix, but I've been looking at it so long i'm going cross eyed

any help would be appreciated, thanks in advance


What does your TEST data set look like? I would expect that there is one measurement for CONC at each time point and they are on different rows of the data. Which would mean that you may want to use a different approach such as LAG to find the appropriate previous 12 hour measure.

And if there are multiple days involved then an actual date might be helpful.

New Contributor
Posts: 3

Re: adding variable values in increments

yes that's right, i have a concentration for each time point..
I have not used LAG before.. any suggestions for implementation?
Esteemed Advisor
Posts: 5,519

Re: adding variable values in increments

Try this:

 

data test;
input time conc;
datalines;
0	1
0.5	2
1	3
1.5	4
2	5
2.5	6
3	7
3.5	8
4	9
4.5	10
5	11
5.5	12
6	13
6.5	14
7	15
7.5	16
8	17
8.5	18
9	19
9.5	20
10	21
10.5	22
11	23
11.5	24
12	25
12.5	26
13	27
13.5	28
14	29
14.5	30
15	31
15.5	32
16	33
16.5	34
17	35
17.5	36
18	37
18.5	38
19	39
19.5	40
20	41
;

proc sql;
create table newTest as
select 
    a.time,
    a.conc,
    a.conc + b.conc as newConc
from 
    test as a left join
    test as b on b.time = a.time + 12;
quit;
PG
Ask a Question
Discussion stats
  • 5 replies
  • 89 views
  • 0 likes
  • 4 in conversation