Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Contact Us
  • Home
  • CDMS
  • Castor CDMS Calculations Manual
  • Introduction to calculations: the basics

Comparing variables with calculation fields in EDC/CDMS

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • CDMS
    Castor CDMS Manual Castor CDMS Calculations Manual Frequently Asked Questions Articles for Data Managers Castor CDMS Compliance Release Documents
  • eConsent
    Castor eConsent Manual Castor eConsent Compliance Release Documents
  • SMS
    Castor SMS Manual Castor SMS Compliance Release Documents
  • Castor Connect
    Castor Connect Compliance Release Documents Castor Connect Manual Castor Connect - Participant Quick Start Guide
  • Helpdesk
    News Other Resources Castor products knowledge resources
  • Status page
  • Completing a Study
+ More

Table of Contents

Comparing two variables Assessing multiple comparisons

Comparing two variables

In calculations, you sometimes need to compare two variables against each other. Check out the article Using the "if-else" logic to see how this works.


For example, you want to check if one value is larger than the other and then show an error message if the condition is true. 


Below is an example that allows you to check if the diastolic blood pressure (diasbp) is larger than the systolic blood pressure (sysbp). 

var dbp = {diasbp};
var sbp = {sysbp};
if(dbp > sbp){
 1;
} else {
 0;
}


You can also use the following operators to compare two variables (instead of '>'):

 < smaller than
 > larger than
 == equal to
 != not equal to
 >= greater than or equal to
 <= less than or equal to


The calculation returns 1 if the dpb is larger than the sbp and 0 if not. To set up a validation message message, use this setup:

  • If this field is equal to 1
  • Show an error (or other type of) message.


You can find a similar calculation here.

Assessing multiple comparisons

Sometimes comparing two variables is not enough and more conditions need to be assessed within an if-else statement. This can be done via two operators:
&& (AND)
|| (OR)


In the following examples you can see the use of these operators.

&& (AND)

var age = {part_age}
var trip = {part_travel}
if(age >= 18 && trip <= 6){
 1;
 }else{
 0;
 }


The result will be 1 only if both conditions are met. In this case, the patient is 18 or older, and has travelled within the previous 6 months.


|| (OR)

var ptrip = {past_trip}
var ftrip = {future_trip}
var tdis = {tropical_disease}
if(ptrip <= 6 || ftrip == 1 || tdis == 1){
 1;
 }else {
 0;
 }


Now, if just one of those conditions occur we will obtain 1. In the example, we obtain 1 if the patient has traveled within the previous 6 months, OR is planning to go on a trip in the future, OR has suffered a tropical disease.


&& and || can be combined but we will need parentheses to organize the operations.


For example:

var age = {part_age}
var ptrip = {past_trip}
var ftrip = {future_trip}
if((age >= 18 && ptrip <= 6) || (age >= 50 && ftrip == 1)) {
1;
}else{
0;
}


The evaluation of the code will happen in two steps: (age >= 18 && ptrip <= 6), (age >= 50 && ftrip == 1) and then ||.


In this example we obtain 1 if one of the blocks in parentheses is true: older than 18 AND traveled in the last 6 months, OR older than 50 AND planning a future trip.


Note


When using < and > with numbers, the value specified is not included. Thus, > 25 is equivalent to >= 26

calculation fields variable comparison

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • Forcing Castor to calculate with empty fields in EDC/CDMS
  • Using the "for loop" in calculations in EDC/CDMS
  • Introduction to calculation fields and syntax in EDC/CDMS
  • Using the "if-else" logic in EDC/CDMS
ISO 27001
FDA - 21 CFR part 11
ICH GCP compliant
HIPAA compliant
CDISC
ISO 9001
gdpr compliant

Products & Industries

  • Electronic Data Capture (EDC)
  • ePRO
  • eConsent
  • Decentralized Clinical Trials (DCT)
  • Clinical Data Management
  • Medical Device & Diagnostics
  • Biotech & Pharma
  • CROs
  • Academic Research

Resources

  • Thought Leadership
  • Blog
  • Castor Academy
  • Knowledge Base

 

Company

  • About Us
  • Careers
  • News
  • Contact Support
  • Contact Us

Legal & Compliance

  • Terms of Use
  • Privacy & Cookie Statement
  • Responsible Disclosure Policy
  • Good Clinical Practice (GCP)
  • ISO Compliance Certificates
  • GDPR & HIPAA Compliance
  • Security Statement

© 2022, Castor. All Rights Reserved.

Follow us on social media


Knowledge Base Software powered by Helpjuice

Definition by Author

0
0
Expand