Data360 Analyze

 View Only
  • 1.  Using conditional statement to create a flag field

    Posted 02-10-2020 13:38

    I have a set of records with a specific code field.  ex: 123221321

    I would like to be able to create a field with a flag that is set to a specific value based on the value of the characters in one or more of the specific positions of the code field.

    ie: flag = 1 if the first character is '1' and the fourth character is '2'

    or flag = 2 if the first character is '2' and the fourth, fifth, and sixth character string is '221'

    How would I go about doing this?



  • 2.  RE: Using conditional statement to create a flag field

    Employee
    Posted 02-10-2020 15:02

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    The ability to substring a string in Python is available to you.

     

    e.g..

    c = in1.Code

    out1.Flag = 1 if c[:1] == '1' and c[3:4] == '2' else 2 if c[:1] == '2' and c[3:6] == '221' else Null

     

    https://guide.freecodecamp.org/python/is-there-a-way-to-substring-a-string-in-python/



  • 3.  RE: Using conditional statement to create a flag field

    Employee
    Posted 02-11-2020 03:07

    One comment to augment Gerry's says above - unless you have previously validated the code field to check whether it contains Null values and replaced those Nulls, you will need to handle this situation within the Python code in the Transform node. The see the example below:

    While the evaluation of substrings is a good choice for this use case you may also be interested in the information in this article which discusses a number of other ways in which you can create 'flag' fields when the criteria are simpler:

    https://support.infogix.com/hc/en-us/community/posts/360028735534-Conditional-Data-Entry-Custom-Node 

     

    Also see  the example here:

    https://support.infogix.com/hc/en-us/community/posts/360028735914-Flag-node

     

     

    Attached files

    Conditional_Statement_Flag - 11 Feb 2020.lna