cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Valerio
Level II

Column Name as Variable (Very Simple)

Dear All,

 

I am struggling with a very simple problem.

 

I need to select a column name using a variable. Please see below:

 

List = {"A","B","C"};
For( 
	i=1, 
	i<=nitems(List), 
	i++, 
	Add Columns from Update Table( :Name(List[i]) )
);

 

However, JMP does not accept anything inside ":Name()" that isn't an explicit quoted string.. In fact, "List[i]" is a quoted string, but the code doesn't even run. 

 

How can I get around this?

 

Thank you!

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: Column Name as Variable (Very Simple)

I assumed you wanted to add a column from the update table to a new table.  I read your code, and specifically the statement

Add Columns from Update Table( :Name(List[i]) )

I am not aware of a JMP statement of this name, and thought you were specifying pseudo code for the action you wanted.

 

If you need to execute this code specifically, you can expand the List reference to a literal string, and execute it

Eval( Parse( "Add Columns from Update Table( :Name(" || List[i] || ") )" ) );

 

Jim

View solution in original post

txnelson
Super User

Re: Column Name as Variable (Very Simple)

Try this.....you need to embed the quotes using the escape sequence

For( 
	i=1,
	i<=nitems(EPIData_to_Get),
	i++,
	Reactors_EPI << New Column( 
		EPIData_to_Get[i], 
		Numeric, Continuous,
		Formula(
			If( :Parameter == EPIData_to_Get[i], 
				:Value
			)
		)
	);
	Eval( Parse( EvalExpr( "Column(Reactors_EPI,:Name(" || EPIData_to_Get[i] || 
	")) << Set Property( \!"Spec Limits\!", {LSL(Expr(Reactors_EPI:LSL)), USL(Expr(Reactors_EPI:USL)), Show Limits(1)} ) " ) ) )
);
Jim

View solution in original post

6 REPLIES 6
txnelson
Super User

Re: Column Name as Variable (Very Simple)

Here is how I would accomplish what you want

New Table( "Big Class",
	Add Rows( 40 ),
	New Column(
		["en" => "name", "ja" => "名前", "x-id" => "S_name_Col", "zh-CN" => "姓名"],
		Character,
		"Nominal",
		Set Property(
			"Notes",
			["en" => "...usually used as a label variable in plots",
			"ja" => "散布図のラベル変数として使用する。",
			"x-id" => "S_usually_used_as_a_label_variable_Not",
			"zh-CN" => "...通常用作图中的标签变量"]
		),
		Set Values(
			{"KATIE", "LOUISE", "JANE", "JACLYN", "LILLIE", "TIM", "JAMES", "ROBERT",
			"BARBARA", "ALICE", "SUSAN", "JOHN", "JOE", "MICHAEL", "DAVID", "JUDY",
			"ELIZABETH", "LESLIE", "CAROL", "PATTY", "FREDERICK", "ALFRED", "HENRY",
			"LEWIS", "EDWARD", "CHRIS", "JEFFREY", "MARY", "AMY", "ROBERT",
			"WILLIAM", "CLAY", "MARK", "DANNY", "MARTHA", "MARION", "PHILLIP",
			"LINDA", "KIRK", "LAWRENCE"}
		),
		Set Display Width( 0 )
	),
	New Column(
		["en" => "age", "ja" => "年齢", "x-id" => "S_age_Col", "zh-CN" => "年龄"],
		Numeric,
		"Ordinal",
		Format( "Fixed Dec", 5, 0 ),
		Set Property(
			"Notes",
			["en" => "Explore data adventurously",
			"ja" => "年齢別にデータを探索する。",
			"x-id" => "S_Explore_data_adventurously_Not",
			"zh-CN" => "大胆地探究数据"]
		),
		Set Values(
			[12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14,
			14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 16, 16,
			16, 17, 17, 17]
		),
		Set Display Width( 0 )
	),
	New Column(
		["en" => "sex", "ja" => "性別", "x-id" => "S_sex_Col", "zh-CN" => "性别"],
		Character( 1 ),
		"Nominal",
		Set Property(
			"Notes",
			["en" => "Explore data adventurously",
			"ja" => "性別でデータを探索する。",
			"x-id" => "S_Explore_data_adventurously_2_Not",
			"zh-CN" => "大胆地探究数据"]
		),
		Set Values(
			{"F", "F", "F", "F", "F", "M", "M", "M", "F", "F", "F", "M", "M", "M",
			"M", "F", "F", "F", "F", "F", "M", "M", "M", "M", "M", "M", "M", "F",
			"F", "M", "M", "M", "M", "M", "F", "F", "M", "F", "M", "M"}
		),
		Set Display Width( 0 )
	),
	New Column(
		["en" => "height",
		"ja" => "身長(インチ)",
		"x-id" => "S_height_Col",
		"zh-CN" => "身高"],
		Numeric,
		"Continuous",
		Format( "Fixed Dec", 5, 0 ),
		Set Property(
			"Notes",
			["en" => "Explore data adventurously",
			"ja" => "データを探索する。二変量の関係のXに指定する。",
			"x-id" => "S_Explore_data_adventurously_3_Not",
			"zh-CN" => "大胆地探究数据"]
		),
		Set Values(
			[59, 61, 55, 66, 52, 60, 61, 51, 60, 61, 56, 65, 63, 58, 59, 61, 62, 65,
			63, 62, 63, 64, 65, 64, 68, 64, 69, 62, 64, 67, 65, 66, 62, 66, 65, 60,
			68, 62, 68, 70]
		),
		Set Display Width( 0 )
	),
	New Column(
		["en" => "weight",
		"ja" => "体重(ポンド)",
		"x-id" => "S_Big_Class_weight_Col",
		"zh-CN" => "体重"],
		Numeric,
		"Continuous",
		Format( "Fixed Dec", 5, 0 ),
		Set Property(
			"Notes",
			["en" => "Explore data adventurously",
			"ja" => "データを探索する。二変量の関係のYに指定する。",
			"x-id" => "S_Explore_data_adventurously_4_Not",
			"zh-CN" => "大胆地探究数据"]
		),
		Set Values(
			[95, 123, 74, 145, 64, 84, 128, 79, 112, 107, 67, 98, 105, 95, 79, 81,
			91, 142, 84, 85, 93, 99, 119, 92, 112, 99, 113, 92, 112, 128, 111, 105,
			104, 106, 112, 115, 128, 116, 134, 172]
		),
		Set Display Width( 0 )
	),
	Set Label Columns( :name )
)
Jim
Valerio
Level II

Re: Column Name as Variable (Very Simple)

I apologize but I do not understand how this could help me..

Maybe I wasn't clear in my question..

txnelson
Super User

Re: Column Name as Variable (Very Simple)

I assumed you wanted to add a column from the update table to a new table.  I read your code, and specifically the statement

Add Columns from Update Table( :Name(List[i]) )

I am not aware of a JMP statement of this name, and thought you were specifying pseudo code for the action you wanted.

 

If you need to execute this code specifically, you can expand the List reference to a literal string, and execute it

Eval( Parse( "Add Columns from Update Table( :Name(" || List[i] || ") )" ) );

 

Jim
Valerio
Level II

Re: Column Name as Variable (Very Simple)

Thank you!

 

My bad for not explaining properly.

 

I have the next level question... I think I have to combine "Parse" with "EvalExpr" but I don't know how...

 

Please see below:

For( 
	i=1,
	i<=nitems(EPIData_to_Get),
	i++,
	Reactors_EPI << New Column( 
		EPIData_to_Get[i], 
		Numeric, Continuous,
		Formula(
			If( :Parameter == EPIData_to_Get[i], 
				:Value
			)
		)
	);
	Eval( Parse( EvalExpr( "Column(Reactors_EPI,:Name(" || EPIData_to_Get[i] || ")) << Set Property( "Spec Limits", {LSL(Expr(Reactors_EPI:LSL)), USL(Expr(Reactors_EPI:USL)), Show Limits(1)} ) " ) ) )
);

Of course, written like this does not work...

 

Can you help?

 

Thank you again!

 

 

txnelson
Super User

Re: Column Name as Variable (Very Simple)

Try this.....you need to embed the quotes using the escape sequence

For( 
	i=1,
	i<=nitems(EPIData_to_Get),
	i++,
	Reactors_EPI << New Column( 
		EPIData_to_Get[i], 
		Numeric, Continuous,
		Formula(
			If( :Parameter == EPIData_to_Get[i], 
				:Value
			)
		)
	);
	Eval( Parse( EvalExpr( "Column(Reactors_EPI,:Name(" || EPIData_to_Get[i] || 
	")) << Set Property( \!"Spec Limits\!", {LSL(Expr(Reactors_EPI:LSL)), USL(Expr(Reactors_EPI:USL)), Show Limits(1)} ) " ) ) )
);
Jim
Valerio
Level II

Re: Column Name as Variable (Very Simple)

You are the best.

 

Thanks!