We’re asking you to select a content label when starting a new topic in the Discussions area. Read more to find out why.
Choose Language Hide Translation Bar
Highlighted
Theresa
Level III

Several questions about data table column value update, thanks

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

//1.how to realize if age<12, then change :age value to "small", other value in :age keep no change

 

//2.how to realize that add "-ABC" to :name to let the whole column change to for example "KATIE-ABC"

//then how to realize that split the :name by "-" , remove the letters after "-""


//3. how to realize if :height>60, and weight has value !=blank, then age value change to "Yes", other value in age keep no change.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: Several questions about data table column value update, thanks

//1.how to realize if age<12, then change :age 
// value to "small", other value in :age keep no change
names default to here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << set name("Example 1a");

// Use the Value Labels column property to change the 
// displayed value, while not changing the actual value
dt:age << set property("value Labels", {12 = "small"});

dt << Oneway( x(:age), y(:height));
//1.how to realize if age<12, then change :age 
// value to "small", other value in :age keep no change
names default to here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << set name("Example 1b");

// Change the actual value of 12 to "small"
// Since the column Age is a numeric column, it will
// have to be changed to Data Type Character before 
// the value can be changed
dt:age << data type(character);

// Now the vlaue can be changed
// The age value in  :age == "12"  has to be in
// double quotes, since the age column has been
// changed to data type character
dt:age[dt<<get rows where(:age == "12")] = "small";

dt << Oneway( x(:age), y(:height));

// A For Each Row() loop could also have been used to
// change the value
/*For Each Row(
	If( :age == "12", :age = "small")
);*/
//2.how to realize that add "-ABC" to :name 
// to let the whole column change to for 
// example "KATIE-ABC"
//then how to realize that split the :name by "-", 
// remove the letters after "-""
names default to here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << set name("Example 2");

// To add the characters to each value of :Name
// just requires a simple For Each Row() with
// a concatenation of "-ABC" to each value
For Each Row(
	dt:Name = dt:Name || "-ABC"
);

// To find the "-" and to get rid of the "-ABC"
// is easily done with a Word() function
// It allows one to parse strings into "words"
// based upon designated delimiters
For Each Row(
	dt:Name = Word(1, :Name, "-" )
);

// The removal of the values after finding the
// "-" can also be accomplished using either
// a Left() function or a Substr() function
// using the returned value from a Contains()
// function to determine where the "-" is
/*For Each Row(
	dt:Name = left(dt:Name,contains(dt:Name,"-") -1 )
);
// or
For Each Row(
	dt:Name = Substr(dt:Name,1, contains(dt:Name,"-") -1 )
);*/
//3. how to realize if :height>60, and weight 
// has value !=blank, then age value change 
// to "Yes", other value in age keep no change.
names default to here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << set name("Example 3");

// Set the value of JACLYN's weight to missing
// to allow for the test case, where the 
// :Height is greater than 60, but the :Weight
// is missing
dt:Weight[4] = .;

// Since the column :height is numeric and a 
// character value of "Yes" is to be placed in
// that column, the column needs to be changed
// to Data Type of Character
dt:Height << data type(character);

// Now a For Each Row() with a two level 
// comparison can be used to change the
// described value
For Each Row(
	If( :Height > "60" & isMissing( :Weight ) == 0,
		:Height = "Yes"
	)
);
Jim

View solution in original post

2 REPLIES 2
Highlighted
txnelson
Super User

Re: Several questions about data table column value update, thanks

//1.how to realize if age<12, then change :age 
// value to "small", other value in :age keep no change
names default to here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << set name("Example 1a");

// Use the Value Labels column property to change the 
// displayed value, while not changing the actual value
dt:age << set property("value Labels", {12 = "small"});

dt << Oneway( x(:age), y(:height));
//1.how to realize if age<12, then change :age 
// value to "small", other value in :age keep no change
names default to here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << set name("Example 1b");

// Change the actual value of 12 to "small"
// Since the column Age is a numeric column, it will
// have to be changed to Data Type Character before 
// the value can be changed
dt:age << data type(character);

// Now the vlaue can be changed
// The age value in  :age == "12"  has to be in
// double quotes, since the age column has been
// changed to data type character
dt:age[dt<<get rows where(:age == "12")] = "small";

dt << Oneway( x(:age), y(:height));

// A For Each Row() loop could also have been used to
// change the value
/*For Each Row(
	If( :age == "12", :age = "small")
);*/
//2.how to realize that add "-ABC" to :name 
// to let the whole column change to for 
// example "KATIE-ABC"
//then how to realize that split the :name by "-", 
// remove the letters after "-""
names default to here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << set name("Example 2");

// To add the characters to each value of :Name
// just requires a simple For Each Row() with
// a concatenation of "-ABC" to each value
For Each Row(
	dt:Name = dt:Name || "-ABC"
);

// To find the "-" and to get rid of the "-ABC"
// is easily done with a Word() function
// It allows one to parse strings into "words"
// based upon designated delimiters
For Each Row(
	dt:Name = Word(1, :Name, "-" )
);

// The removal of the values after finding the
// "-" can also be accomplished using either
// a Left() function or a Substr() function
// using the returned value from a Contains()
// function to determine where the "-" is
/*For Each Row(
	dt:Name = left(dt:Name,contains(dt:Name,"-") -1 )
);
// or
For Each Row(
	dt:Name = Substr(dt:Name,1, contains(dt:Name,"-") -1 )
);*/
//3. how to realize if :height>60, and weight 
// has value !=blank, then age value change 
// to "Yes", other value in age keep no change.
names default to here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << set name("Example 3");

// Set the value of JACLYN's weight to missing
// to allow for the test case, where the 
// :Height is greater than 60, but the :Weight
// is missing
dt:Weight[4] = .;

// Since the column :height is numeric and a 
// character value of "Yes" is to be placed in
// that column, the column needs to be changed
// to Data Type of Character
dt:Height << data type(character);

// Now a For Each Row() with a two level 
// comparison can be used to change the
// described value
For Each Row(
	If( :Height > "60" & isMissing( :Weight ) == 0,
		:Height = "Yes"
	)
);
Jim

View solution in original post

Highlighted
Theresa
Level III

Re: Several questions about data table column value update, thanks

thank you so much. all are work, only the last one can't work, i initiative a new ticket, and put the pic in the discussion, could you help check ? May peace with you.