BookmarkSubscribeRSS Feed
klinz
Calcite | Level 5

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

5 REPLIES 5
pau13rown
Lapis Lazuli | Level 10

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

klinz
Calcite | Level 5
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..
ballardw
Super User

@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.

klinz
Calcite | Level 5
yes that's right, i have a concentration for each time point..
I have not used LAG before.. any suggestions for implementation?
PGStats
Opal | Level 21

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 358 views
  • 0 likes
  • 4 in conversation