Hello,
I have to derive aval based on conditional strategies.
"in the following order of priority:
1) Check "SWREL". If aval eq 1: Composite strategy 2 using "EASITOTA" as the source score
if swrel = 1 then flg currently will be 'Composite Strategy 2'. if swrel = 0 for all records per subject flag will be blank at this stage
2) Check "RTT1L28D” and “TCM2”. If aval eq 1: Composite strategy 1 using "EASITOTA" as the source score
if either tcm2 or rtt1l28 = 1 along with swrel = 1 then flg will change from "Composite Strategy 2 " to "Composite Strategy 1" .
If swrel,rtt1l28,tcm2 all = 0 for all records per subject then flag will be blank at this stage
2) Check "SWNREL" aval eq 1: While-on-Treatment strategy.
if swnrel = 1 and tcm2 or rtt1l28= 1 then flg will be 'While-on-Treatment'.
3) Apply treatment policy strategy – use data as collected in “EASITOTA”"
If swrel,rtt1l28,tcm2,swnrel all = 0 for all records per subject then flag will be 'treatment policy'
Programming logic
"1)If AVAL = 1 for "SWREL" , apply Composite strategy 2 using "EASITOTA" aval. 2) If AVAL equals 1 on either record where "RTT1L28D" or "T2CM", apply Composite strategy 1 using "EASITOTA" aval. 3) If SWNREL equals 1 on the record, apply While-on-Treatment strategy. 4) Apply Treatment Policy strategy using "EASITOTA" aval."
Here is the data in it's merged form with all relevant variables. For context the aval for SWREL, SWNREL, TCM2 and RTT1L28 represent intercurrent events and the score (AVAL) was transposed to the EASITOTA dataset and a value of 1 indicates an intercurrent event occurred and a value of 0 indicates no intercurrent event.
data have;
input PARAMCD $ SUBJID $ AVISITN :8. ADT :$9. AVAL :8. RTT1L28D :8. T2CM :8. SWREL :8. SWNREL :8.;
infile datalines dlm = '|';
datalines;
EASITOTA|1001|20|27APR2022|13.4|0|0|0|0
EASITOTA|1001|30|11MAY2022|13.4|0|0|0|0
EASITOTA|1001|40|26MAY2022|13.4|0|0|0|0
EASITOTA|1001|50|22JUN2022|13.4|0|0|0|0
EASITOTA|1001|60|20JUL2022|13.4|0|0|0|0
EASITOTA|1001|70|31AUG2022|13.4|0|0|0|0
EASITOTA|1002|20|27APR2022|16.4|0|0|0|0
EASITOTA|1002|30|11MAY2022|16.4|0|0|0|0
EASITOTA|1002|40|25MAY2022|16.4|1|0|0|0
EASITOTA|1002|50|22JUN2022|16.4|1|0|0|0
EASITOTA|1002|60|20JUL2022|16.4|1|0|0|0
EASITOTA|1002|70|22AUG2022|16.4|1|0|0|0
EASITOTA|1003|20|07JUN2022|15.8|0|0|1|0
EASITOTA|1003|20|21JUN2022|15.8|1|0|1|0
EASITOTA|1003|30|05JUL2022|15.8|1|0|1|0
EASITOTA|1003|40|02AUG2022|15.8|0|0|1|0
EASITOTA|1003|50|30AUG2022|15.8|0|0|1|0
EASITOTA|1003|60|27SEP2022|15.8|0|0|1|0
EASITOTA|1003|70|25OCT2022|15.8|0|0|1|0
;
run;
Basically I would like to create a flag that assigns the correct strategy to all records per subject so I can further go on to derive aval (based on these strategies below). I was thinking that a conditional dow loop may work here but if there is a simpler approach I would really appreciate it.
Do you mean something like this:
data have;
input PARAMCD $ SUBJID $ AVISITN :8. ADT :$9. AVAL :8. RTT1L28D :8. T2CM :8. SWREL :8. SWNREL :8.;
infile datalines dlm = '|';
datalines;
EASITOTA|1001|20|27APR2022|13.4|0|0|0|0
EASITOTA|1001|30|11MAY2022|13.4|0|0|0|0
EASITOTA|1001|40|26MAY2022|13.4|0|0|0|0
EASITOTA|1001|50|22JUN2022|13.4|0|0|0|0
EASITOTA|1001|60|20JUL2022|13.4|0|0|0|0
EASITOTA|1001|70|31AUG2022|13.4|0|0|0|0
EASITOTA|1002|20|27APR2022|16.4|0|0|0|0
EASITOTA|1002|30|11MAY2022|16.4|0|0|0|0
EASITOTA|1002|40|25MAY2022|1 |1|0|0|0
EASITOTA|1002|50|22JUN2022|16.4|1|0|0|0
EASITOTA|1002|60|20JUL2022|16.4|1|0|0|0
EASITOTA|1002|70|22AUG2022|16.4|1|0|0|0
EASITOTA|1003|20|07JUN2022|15.8|0|0|1|0
EASITOTA|1003|20|21JUN2022|15.8|1|0|1|0
EASITOTA|1003|30|05JUL2022|15.8|1|0|1|0
EASITOTA|1003|40|02AUG2022|15.8|0|0|1|0
EASITOTA|1003|50|30AUG2022|1 |0|0|1|0
EASITOTA|1003|60|27SEP2022|15.8|0|0|1|0
EASITOTA|1003|70|25OCT2022|15.8|0|0|1|0
;
run;
proc print; run;
/*
1) If AVAL = 1 for "SWREL" , apply Composite strategy 2 using "EASITOTA" aval.
2) If AVAL equals 1 on either record where "RTT1L28D" or "T2CM", apply Composite strategy 1 using "EASITOTA" aval.
3) If SWNREL equals 1 on the record, apply While-on-Treatment strategy.
4) Apply Treatment Policy strategy using "EASITOTA" aval.
*/
proc format;
value strategy
1 = "Composite strategy 2"
2 = "Composite strategy 1"
3 = "While-on-Treatment strategy"
4 = "Treatment Policy strategy"
other = "ERROR"
;
run;
data want;
format strategy strategy.;
do _N_ = 1 by 1 until(last.SUBJID);
set have;
by SUBJID;
select;
when (AVAL = 1 and SWREL) row_st = 1;
when (AVAL = 1 and (RTT1L28D or T2CM)) row_st = 2;
when (SWNREL) row_st = 3;
otherwise row_st = 4;
end;
strategy = min(strategy,row_st);
end;
do _N_ = 1 to _N_;
set have;
output;
end;
run;
proc print;
run;
Bart
I have to say that I cannot follow what is intended by any of priorities 1 through 4.
Examples of interpretation:
What are we checking SWREL for what/how and what indication that it has been checked (since this step is apparently needed for the second)? When checking "RTT1L28D” and “TCM2” is that each variable individually or combinations of the two, for what and how to indicate "checked"?
What is a "Composite Strategy"? What variables are involved and how?
What is a "source score"? How is it used? what variables?
What is an "intercurrent event"? Variables and values needed to tell what one is?
What is "While-on treatment strategy"? Variables and values to use?
How to apply a "treatment policy strategy"?
And what exactly does "if no changes to data in step 1" mean? For specific records? Specific value combinations of some variables? The entire data set?
You may have to talk us through some specific examples. These priorities are a pretty good example of very specific to one field jargon and need translation to anyone working outside of that field and possibly your organization. So clear definitions and expected results at each step are needed.
What are we checking SWREL for what/how and what indication that it has been checked (since this step is apparently needed for the second)?
SWREL is an intercurrent event and a value of 1 represents it occured and 0 it didn't
When checking "RTT1L28D” and “TCM2” is that each variable individually or combinations of the two, for what and how to indicate "checked"?
that either has a value of 1 or 0
What is a "Composite Strategy"? What variables are involved and how?
Not needed. It is what I'll be using to derive aval but would like a flag to indicate which strategy per subject I use based on the iterative ranking process
What is a "source score"? How is it used? what variables?
synonym for AVAL column
What is an "intercurrent event"? Variables and values needed to tell what one is?
Updated post to give as much information as needed
What is "While-on treatment strategy"? Variables and values to use?
same idea as composite strategy. will be a term for the flag value
How to apply a "treatment policy strategy"?
same idea as composite strategy. will be a term for the flag value
And what exactly does "if no changes to data in step 1" mean? For specific records? Specific value combinations of some variables? The entire data set?
All records per subject
I've updated the post to make things clearer
Do you mean something like this:
data have;
input PARAMCD $ SUBJID $ AVISITN :8. ADT :$9. AVAL :8. RTT1L28D :8. T2CM :8. SWREL :8. SWNREL :8.;
infile datalines dlm = '|';
datalines;
EASITOTA|1001|20|27APR2022|13.4|0|0|0|0
EASITOTA|1001|30|11MAY2022|13.4|0|0|0|0
EASITOTA|1001|40|26MAY2022|13.4|0|0|0|0
EASITOTA|1001|50|22JUN2022|13.4|0|0|0|0
EASITOTA|1001|60|20JUL2022|13.4|0|0|0|0
EASITOTA|1001|70|31AUG2022|13.4|0|0|0|0
EASITOTA|1002|20|27APR2022|16.4|0|0|0|0
EASITOTA|1002|30|11MAY2022|16.4|0|0|0|0
EASITOTA|1002|40|25MAY2022|1 |1|0|0|0
EASITOTA|1002|50|22JUN2022|16.4|1|0|0|0
EASITOTA|1002|60|20JUL2022|16.4|1|0|0|0
EASITOTA|1002|70|22AUG2022|16.4|1|0|0|0
EASITOTA|1003|20|07JUN2022|15.8|0|0|1|0
EASITOTA|1003|20|21JUN2022|15.8|1|0|1|0
EASITOTA|1003|30|05JUL2022|15.8|1|0|1|0
EASITOTA|1003|40|02AUG2022|15.8|0|0|1|0
EASITOTA|1003|50|30AUG2022|1 |0|0|1|0
EASITOTA|1003|60|27SEP2022|15.8|0|0|1|0
EASITOTA|1003|70|25OCT2022|15.8|0|0|1|0
;
run;
proc print; run;
/*
1) If AVAL = 1 for "SWREL" , apply Composite strategy 2 using "EASITOTA" aval.
2) If AVAL equals 1 on either record where "RTT1L28D" or "T2CM", apply Composite strategy 1 using "EASITOTA" aval.
3) If SWNREL equals 1 on the record, apply While-on-Treatment strategy.
4) Apply Treatment Policy strategy using "EASITOTA" aval.
*/
proc format;
value strategy
1 = "Composite strategy 2"
2 = "Composite strategy 1"
3 = "While-on-Treatment strategy"
4 = "Treatment Policy strategy"
other = "ERROR"
;
run;
data want;
format strategy strategy.;
do _N_ = 1 by 1 until(last.SUBJID);
set have;
by SUBJID;
select;
when (AVAL = 1 and SWREL) row_st = 1;
when (AVAL = 1 and (RTT1L28D or T2CM)) row_st = 2;
when (SWNREL) row_st = 3;
otherwise row_st = 4;
end;
strategy = min(strategy,row_st);
end;
do _N_ = 1 to _N_;
set have;
output;
end;
run;
proc print;
run;
Bart
Perfect thanks a lot!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.