cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
lazzybug
Level III

How to replace :column_name with variable in JMP JSL?

@jthiCan you help me to fix the code error below? How to use variable to replace :column name in the correct way? Thank you so much for your help.

 

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
hvar = "height";
gvar = "sex";

std = Col Std Dev( if(Excluded( Row State() ) == 0 & column(gvar) =="M", column(hvar) ));

//std = Col Std Dev( if(Excluded( Row State() ) == 0 & :sex =="M", column(hvar) ));
show(std);
2 ACCEPTED SOLUTIONS

Accepted Solutions
pmroz
Super User

Re: How to replace :column_name with variable in JMP JSL?

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
hvar = "height";
gvar = "sex";

std = Col Std Dev( if(!Excluded( Row State() ) & as column(dt, gvar) == "M", as column(dt, hvar) ));

//std = Col Std Dev( if(Excluded( Row State() ) == 0 & :sex =="M", column(hvar) ));
show(std);

Sometimes you need to use "as column".  Sometimes just "column".

View solution in original post

jthi
Super User

Re: How to replace :column_name with variable in JMP JSL?

How you replace it depends on the use case, in your case using AsColumn as @pmroz suggested is the easiest option.

Few links

Below are few other options but they do require more scripting which is usually unnecessary in this type of cases

 

Names Default To Here(1);

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

hvar = "height";
gvar = "sex";

// As Column
std = Col Std Dev(If(!Excluded(Row State()) & As Column(dt, gvar) == "M", As Column(dt, hvar)));

// Data table subscripting
// https://community.jmp.com/t5/Uncharted/Data-table-subscripting/ba-p/21013
rows_of_interest = dt << Get Rows Where(Excluded(Row State()) == 0 & Column(gvar)[] == "M");
std2 = Std Dev(dt[rows_of_interest, hvar]);

// Build and evaluate expression
// https://community.jmp.com/t5/JSL-Cookbook-Archived/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/ta-p/48998
std3 = Eval(Substitute(
	Expr(Col Std Dev(If(!Excluded(Row State()) & groupcol == "M", numcol))),
	Expr(groupcol), Name Expr(AsColumn(gvar)),
	Expr(numcol), Name Expr(AsColumn(hvar))
));

// Check
std4 = Col Std Dev(If(Excluded(Row State()) == 0 & :sex == "M", :height));

show(std, std2, std3, std4);

 

-Jarmo

View solution in original post

3 REPLIES 3
pmroz
Super User

Re: How to replace :column_name with variable in JMP JSL?

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
hvar = "height";
gvar = "sex";

std = Col Std Dev( if(!Excluded( Row State() ) & as column(dt, gvar) == "M", as column(dt, hvar) ));

//std = Col Std Dev( if(Excluded( Row State() ) == 0 & :sex =="M", column(hvar) ));
show(std);

Sometimes you need to use "as column".  Sometimes just "column".

lazzybug
Level III

Re: How to replace :column_name with variable in JMP JSL?

Thank you so much. This works very well.

jthi
Super User

Re: How to replace :column_name with variable in JMP JSL?

How you replace it depends on the use case, in your case using AsColumn as @pmroz suggested is the easiest option.

Few links

Below are few other options but they do require more scripting which is usually unnecessary in this type of cases

 

Names Default To Here(1);

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

hvar = "height";
gvar = "sex";

// As Column
std = Col Std Dev(If(!Excluded(Row State()) & As Column(dt, gvar) == "M", As Column(dt, hvar)));

// Data table subscripting
// https://community.jmp.com/t5/Uncharted/Data-table-subscripting/ba-p/21013
rows_of_interest = dt << Get Rows Where(Excluded(Row State()) == 0 & Column(gvar)[] == "M");
std2 = Std Dev(dt[rows_of_interest, hvar]);

// Build and evaluate expression
// https://community.jmp.com/t5/JSL-Cookbook-Archived/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/ta-p/48998
std3 = Eval(Substitute(
	Expr(Col Std Dev(If(!Excluded(Row State()) & groupcol == "M", numcol))),
	Expr(groupcol), Name Expr(AsColumn(gvar)),
	Expr(numcol), Name Expr(AsColumn(hvar))
));

// Check
std4 = Col Std Dev(If(Excluded(Row State()) == 0 & :sex == "M", :height));

show(std, std2, std3, std4);

 

-Jarmo