Null output for Recode Script based on RangesHello,
I'm trying to create a new column (PRR_Level) that groups data from a continuous numeric column (PRR_Score) into 2 categories. The code generated from using the recode function and mapping by value works by creating a map for each value in PRR_Score, but I want something more concise I can use for repeat analyses.
This script generates no errors but all values in the new column are null. Does anyone have any ideas what I am doing wrong?
//PRR_Level
Names Default To Here( 1 );
dt = Current Data Table();
dt << Begin Data Update;
dt << New Column( "PRR_Level",
For Each Row(
:PRR_Level = If(
:PRR_Score >= 75, "Preferred Fit",
:PRR_Score < 75, "Potential Risk",
)
);
);
dt << Move Selected Column( to last );
dt << End Data Update;
ScriptingRe: Null output for Recode Script based on RangesThe output values are strings, therefore the new column must be declared as a character modeling type for the column.
Also, the For Each Row() function, is an open code function and requires a fuller structure for the assignment statements. I have provided two method of creating the column you want
//PRR_Level
Names Default To Here( 1 );
dt = Current Data Table();
dt << New Column( "PRR_Level", character );
For Each Row(
If( :PRR_Score >= 75,
:PRR_Level = "Preferred Fit",
:PRR_Level = "Potential Risk"
)
);
// or
dt << New Column( "PRR_Level 2",
character,
Set each value(
If( :PRR_Score >= 75,
"Preferred Fit",
"Potential Risk"
)
)
);