Hello,
I'm so grateful for all of the previous replies, and am learning more and more about JSL every day. At this point, I am comfortable with the basics, and have learned about For loops, For Each Row and use of the Formula function. This was very helpful. As I mentioned in my previous post, I'm working on a dataset, and have 4 key columns:
1) PATIENTID: list of unique values for patient number
2) VALUE: Value of a patient rating at a particular timepoint
3) TIME: Timepoint at which patient rating was collected
4) PARAM: The patient rating is comprised of 4 individual items and a total score (ITEM1, ITEM2, ITEM3, ITEM4 and TOTAL). The total score is simply a sum of ITEM1+ITEM2+ITEM3+ITEM4.
From this, I'd like to create a 5th column (called "TEST"). The value for TEST is based on the following logic:
For an individual patient, if baseline values are:
- TOTAL > 9 or
- 1 of ITEM1, ITEM2, ITEM3 or ITEM4 are > 3 or
- 3 of ITEM1, ITEM2, ITEM3 or ITEM4 are > 2
Then the corresponding row in "TEST" should be evaluated as "YES". Non-baseline values, and other values should be evaluated as "NO". This logic should be iterated to every patient and every row in the datatable.
I'm having problems iterating through the rows in my dataset. Reason is that each patient has differing number of timepoints that they had filled out the scale. Some patients dropped out early. Since each patient has a different number of rows, I'm having difficulty figuring out how to iterate through the rows to write the script.
I've tried combining some IF statements, but get stuck at the point where I need to iterate to the next patient ID. I'm attaching a script that I wrote, but got stuck. Any help is greatly appreciated.
Names Default To Here( 1 );
dt = current data table ();
dt << New Column ("TEST", Character, Formula(
If(:TIME == "BASELINE",
theRow = Row();
thePatient = :PATIENTID;
If(:PARAM == "TOTAL",
If(N Rows(dt << Get Rows Where(
Row()>=theRow &
thePatient == :PATIENTID &
:VALUE > 9
)
) > 0
,"YES"
,"NO"
)))
));
Here is an example of what the data table looks like (real patient information redacted for privacy)