How do I change a variable's type?

Mahshid
Mahshid
Altair Employee
edited May 2021 in Community Q&A

There are a couple of ways to change the variable type.

Option 1: It can be done in the import node on the 'Field Transformer' page. Just change the 'Target Type' here. This is also where you can apply date/time masks.

For those wondering the 'Precision' field option allows you to select decimal accuracy for numbers, and substrings for text e.g. '4' will take the first 4 characters, and '-4' takes the last 4 characters.

image

image
Option 2: Using the 'Variable Transformations' node you are able to use the CAST function, such as 'CAST ([variable_name] AS <target type>)'.

 

image

Another thing worth remembering is the variable transform node tends to set the type as the first object it sees, so a workaround is to do something like "1*[hours-per-week]" or ''+ number-hours-worked (that's a double apostrophe signifying an empty string).

The results for the converting [education] will be the same, but beware that when converting a string to a number the result will be 0 if the value doesn't start with a number e.g. "ABC123", or the first continuous set of numbers that the tool sees if it can, e.g. '7th-8th' will return "7" and drop the "8".





------------------------------
Altair Data Science Team
Toronto ON
------------------------------

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.