Hello,
Okay let me try sub setting to two subjects. So it's basically a conditional Last observation carried forward approach. USUBJID 1001 because all the events (RTT1L28,SWNREL,T2SWREL) did not occur they all have results of 0 so the result (AVAL) for that subject at that visit is retained for the AVAL for the new created record (TOTEDPS1). USUBJID 1002 follows the same pattern until week 4 where an event has occurred for RTT1L28 indicated by a value of 1. So we have to retain the most recent visit where all the events (RTT1L28,SWNREL,T2SWREL) = 0 so in this case Week 2 and that week 2 AVAL (13.8) will be used for every other visits (Week 4, 8,12,16) because of that RTT1L28 value of 1 being present for all those visits (I've realised Week 16 in the data previously provided should also be 13.8- apologies). If a value of SWNREL had a value of 1 at a particular visit then the TOTEDPS1 record would be created but would be set to missing. If an unscheduled visit occurred then the TOTEDPS1 record would not be created but is still considered as a value to be carried forward. For example, if the AVAL (say 4) had all the events (RTT1L28,SWNREL,T2SWREL) = 0 and then subsequent visit (for example Week 4) had all RTT1L28,T2SWREL = 1 then the Unscheduled AVAL of 4 would be imputed/carried forward as the most recent value. Hopefully that makes sense. Here is a rough attempt at coding
data TOTEDPS1 (where= (paramcd= 'EASITOTA') keep= subjid ablfl paramcd aval_ visit visitnum aval rtt1l28d t2swrel swnrel avisitn lag_value);
length paramcd $ 20 ;
set adeasint_m;
by usubjid avisitn;
array columns {3} rtt1l28d t2swrel swnrel;
lag_value=lag(aval);
do i = 1 to dim(columns);
if abs(columns {i}) >0 then DO;
paramcd= 'TOTEDPS1';
aval_=lag_value;
end;
else do;
paramcd= 'TOTEDPS1';
aval_=aval;
end;
end;
run;
data want;
input PARAMCD $ USUBJID $ VISIT $ AVAL :8. ABLFL :$ AVISITN :8. RTT1L28D :8. SWNREL :8. T2SWREL :8.;
infile datalines dlm = '|';
datalines;
EASITOTA|1001|Screening|16| |10|0|0|0
TOTEDPS1|1001|Screening|16| |10|0|0|0
EASITOTA|1001|Day 1 |13.4| |20|0|0|0
TOTEDPS1|1001|Day 1 |13.4| |20|0|0|0
EASITOTA|1001|Week 2 |8.1| |30|0|0|0
TOTEDPS1|1001|Week 2 |8.1| |30|0|0|0
EASITOTA|1001|Week 4 |5.6| |40|0|0|0
TOTEDPS1|1001|Week 4 |5.6| |40|0|0|0
EASITOTA|1001|Week 8 |6| |50|0|0|0
TOTEDPS1|1001|Week 8 |6| |50|0|0|0
EASITOTA|1001|Week 12 |8.7| |60|0|0|0
TOTEDPS1|1001|Week 12 |8.7| |60|0|0|0
EASITOTA|1002|Screening|14| |10|0|0|0
TOTEDPS1|1002|Screening|14| |10|0|0|0
EASITOTA|1002|Day 1 |16.4|Y|20|0|0|0
TOTEDPS1|1002|Day 1 |16.4|Y|20|0|0|0
EASITOTA|1002|Week 2 |13.8| |30|0|0|0
TOTEDPS1|1002|Week 2 |13.8| |30|0|0|0
EASITOTA|1002|Week 4 |21.4| |40|1|0|0
TOTEDPS1|1002|Week 4 |13.8| |40|1|0|0
EASITOTA|1002|Week 8 |14| |50|1|0|0
TOTEDPS1|1002|Week 8 |13.8| |50|1|0|0
EASITOTA|1002|Week 12 |15.6| |60|1|0|0
TOTEDPS1|1002|Week 12 |13.8| |60|1|0|0
EASITOTA|1002|Week 16 |21.4| |70|1|0|0
TOTEDPS1|1002|Week 16 |13.8| |70|1|0|0
... View more