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

Flagging an error if variable name does not match

Hi all,

 

I want to build a simple error trap where it will flag the error if the variable name from the user defined variable name with the existing table variable name. For example as below;

 

User defined Data table

Variable Name

1. Benzene

2. Methane

3. Ethane 

 

Existing Data Table

Variable Name

1. Benzene

2. Methane

3. Ethane 

4. Propane

5. Pentane

6. Hexane

 

I tried to used !contains function, but it seemed that I dont use the syntax properly. I'm a very new to jmp script, so I'm seeking for anyone in the community help

Inputdt = User Defined Data Table Name
mvdt = Existing Data Table Name

//Get required variable lists from user define Data Table

varListInput = Column( Inputdt, "Variable Name" ) << get values;

// Error trap - if # UserDefinedTable & # Existing Data Table variables don't match, then break code & output error message. 
//Obtain column names from existing Data Table from list
colnames = mvdt << get column names( string );

show(colnames);
show(varListInput);

If(!contains Item ("colnames", "varListInput"),
	Message = Dialog( "The Variable Name does not match with Existing Data Table.Please correct your Input Table." );
	Stop();
);
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Flagging an error if variable name does not match

The Contains Items() function requires the data to be in Associative Arrays.  If your items are in lists, the below method will work.

Inputdt = User Defined Data Table Name
mvdt = Existing Data Table Name;

//Get required variable lists from user define Data Table

varListInput = Column( Inputdt, "Variable Name" ) << get values;

// Error trap - if # UserDefinedTable & # Existing Data Table variables don't match, then break code & output error message. 
//Obtain column names from existing Data Table from list
colnames = mvdt << get column names( string );

show(colnames);
show(varListInput);

For( i = 1, i <= N Items( varListInput ), i++,
	If( !Contains( colnames, varListInput[i] ),
		Message = Dialog(
			"The Variable Name does not match with Existing Data Table.Please correct your Input Table."
		);
		Stop();
	)
);
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Flagging an error if variable name does not match

The Contains Items() function requires the data to be in Associative Arrays.  If your items are in lists, the below method will work.

Inputdt = User Defined Data Table Name
mvdt = Existing Data Table Name;

//Get required variable lists from user define Data Table

varListInput = Column( Inputdt, "Variable Name" ) << get values;

// Error trap - if # UserDefinedTable & # Existing Data Table variables don't match, then break code & output error message. 
//Obtain column names from existing Data Table from list
colnames = mvdt << get column names( string );

show(colnames);
show(varListInput);

For( i = 1, i <= N Items( varListInput ), i++,
	If( !Contains( colnames, varListInput[i] ),
		Message = Dialog(
			"The Variable Name does not match with Existing Data Table.Please correct your Input Table."
		);
		Stop();
	)
);
Jim
jacksonperry
Level I

Re: Flagging an error if variable name does not match

Thank you, it is working fine now