- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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);
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Column() vs As Column() vs datable:column vs dt:As name("column")
- Referencing a Column in JSL
- JSL Syntax Reference - As Column
- JSL Syntax Reference - Column()
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to replace :column_name with variable in JMP JSL?
Thank you so much. This works very well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Column() vs As Column() vs datable:column vs dt:As name("column")
- Referencing a Column in JSL
- JSL Syntax Reference - As Column
- JSL Syntax Reference - Column()
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);