Data360 Analyze

 View Only
  • 1.  Look for zip code less than 5 digits

    Employee
    Posted 05-19-2022 14:47

    Hello, 

    I'm looking for a way to look at the zip code field in my data and determine if it is less than 5 digits in length.  

     

    Thanks

    Mike

     



  • 2.  RE: Look for zip code less than 5 digits

    Posted 05-20-2022 00:45

    Hi Mike,

    The transform node could gives you any number of ways to do this with some fairly simple Python.

    For an even easier solution we can use the Filter node's "Advanced" feature to add the python function of LEN() to count the length of the test and filter record in or out.

    simply swap the field name on your input pin for the 'ZipCode' field I created in the example above.

    This example filter find all the records with less than (<) a length of 5 characters. You can swap the '<' character for;

    • '!=' to show all records that DO NOT have a length of 5 (that way to could get the ones over 5 at the same time)  
    • "==" to just return the records WITH a length of 5. Good if you wanted to removed the bad records and continue
    • ">" to show only the records with a length OVER 5 characters

     

    One could take this one step further and use a "split" node, which uses the same underlying code as the filter node, but not only do you get the matches for your filter criteria, you get the records that don't match on a 2nd output pin.

    In the example above you can see we get the 4 records that are under a length of 5 on the 1st pin and the 11 records that are the perfect length of 5 on the 2nd pin, really cool to progress your flow and still exception manage those 'bad' records with an email alert or writing them off to a file.

    Have a play and let us know how you get on :)

    Good luck!

    John



  • 3.  RE: Look for zip code less than 5 digits

    Employee
    Posted 05-20-2022 02:51

    You can also use regular expressions in a Transform node to identify strings with a zip or zip+4 formats:

    ConfigureFields Script

    ProcessRecords Script

    Example results:

    See the attached example data flow

     

    Attached files

    Check_Zip_Code_Validity - 20 May 2022.lna

     



  • 4.  RE: Look for zip code less than 5 digits

    Employee
    Posted 05-20-2022 06:39

    Adrian, John, 

    Thanks to both of you for responding.  Both solutions worked great!  John, I did have to account for NULL in my data but I just put a split node in front of your filter solution and it worked fine.  Thanks again.