Question: I have a data table with data values in upper and lower case text strings in one column.
I expect that the code will need to loop through each row, select the column of interest and set the value in the column to uppercase. I am having an issue figuring out the correct syntax to do this. This is what I have so far, but don't think I am close enough. Thanks to any help that can be provided.
For( k = 1, k <= N Rows( dt3 ), k++,
Column( dt, :KEYWORD)[k] = UpperCase( Column( dt, :KEYWORD)[k]) );
So you are foring through the number rows in dt3 but affecting dt seems like an issue first off. Plus the syntax is either :Keyword[k] or Column(dt, "Keyword")[k] or dt:Keyword[k].
Here's a corrected one
Names Default to Here( 1 );
dt = new table("Test",
New Column("Keyword", character, <<Set Values({"abC", "Def", "ABC", "abcdfe"}))
);
For( k = 1, k <= N Rows( dt/*dt3*/ ), k++,
//Column( dt, :KEYWORD)[k] = UpperCase( Column( dt, :KEYWORD)[k])
Column(dt, "Keyword")[k] = UPPERCASE(Column(dt, "KEYWORD")[k]);
//or
//:Keyword[k] = Uppercase(:Keyword[k]);
);
But it'd likely be faster to just do all of them at once and set values.
values = Column(dt, "Keyword") << Get Values();
u_values = parse(uppercase(char(values)));
Column(dt, "Keyword") << Set values(u_values);
So you are foring through the number rows in dt3 but affecting dt seems like an issue first off. Plus the syntax is either :Keyword[k] or Column(dt, "Keyword")[k] or dt:Keyword[k].
Here's a corrected one
Names Default to Here( 1 );
dt = new table("Test",
New Column("Keyword", character, <<Set Values({"abC", "Def", "ABC", "abcdfe"}))
);
For( k = 1, k <= N Rows( dt/*dt3*/ ), k++,
//Column( dt, :KEYWORD)[k] = UpperCase( Column( dt, :KEYWORD)[k])
Column(dt, "Keyword")[k] = UPPERCASE(Column(dt, "KEYWORD")[k]);
//or
//:Keyword[k] = Uppercase(:Keyword[k]);
);
But it'd likely be faster to just do all of them at once and set values.
values = Column(dt, "Keyword") << Get Values();
u_values = parse(uppercase(char(values)));
Column(dt, "Keyword") << Set values(u_values);
Thank you for the quick solutions. It's nice to see two ways of doing this. Looks like I was close on the first one. Tested both and they work and will use the second one since it is faster.
Appreciate the help!
The For Each Row() function will automatically loop through all rows in the data table, so the below is another way of handling your question
For Each Row( As Column( dt, "keyword" ) = Lowercase( As Column( dt, "keyword" ) ) );
Be a little cautious with the function, in that you can not have a For Each Row() function within another For Each Row() function
Not sure if a script is necessary. Select the column with the character data, select Cols > Recode. Changing case is a built-in operation.