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
Aam_jmp
Level IV

Comparing rows and columns with special characters

This might be very easy but I am new to JMP and finding it difficult to find a solution to this error.

Unexpected "%". Perhaps there is a missing "," or ")".

Scoped data table access requires a data table column or variable in access or evaluation of dt1: Acidic Variant' , dt1:Acidic Variant /*###*/

I am simply comparing a row in one table with columns of the other table. It does work for row and column names which do not have special characters like % or () but I will have names which will have special characters. Can anyone point out to me how this can be handled? Any help much appreciated. Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Comparing rows and columns with special characters

Here is a modification to your script that will allow it to work.  You were heading down the correct path, you just needed to use the :Name() function in the Substitute function

Names Default to Here(1);
dt1 = Data Table( "Example1" );
dt2 = Data Table( "Example2" );

a = N Rows( dt2 );
colNamesList = dt1 << get column names( string );

For( i = 1, i < a, i++,
	Eval(
		Substitute(
				Expr(
					If( Try( __col__ << get name, "" ) != "",
						__col__ << Set Property(
							"Spec Limits",
							{LSL( _LSL_ ), USL( _USL_ ), Target( _Target ), Show Limits( 1 )}
						)
					)
				),
			Expr( __col__ ), Parse( "dt1:Name(\!"" || Column( dt2, "ColumnName" )[i] || "\!")" ),
			Expr( _LSL_ ), dt2:LSL[i],
			Expr( _USL_ ), dt2:USL[i],
			Expr( _Target ), dt2:Target[i], 

		)

	)
);

Also, I added in a check to make sure the column is found in the target data table, so the script does not error out, and stop processing before all records are processed.

Jim

View solution in original post

20 REPLIES 20
uday_guntupalli
Level VIII

Re: Comparing rows and columns with special characters

@Aam_jmp
        If the % symbol is part of your column name, like let us say column name is "%x", then try using Name() function to identify the column. If you could provide a sample data set and your script, we can look at it to see whats wrong 

 

 

Best
Uday
Aam_jmp
Level IV

Re: Comparing rows and columns with special characters

The names are like this: Titer (%) 1, Titer(%) 2 and so forth
uday_guntupalli
Level VIII

Re: Comparing rows and columns with special characters

@Aam_jmp
         Please kindly re-read my response and try using the following sample. The Name function will be able to handlt the problem you have. I am posting a sample of the same. Unless you share your script and sample data, it is hard to see what is causing the error. 

 

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

MeanWeight = Col Sum(dt:weight); // Calculate Column Mean 

dt << New Column("% of Total Weight",Numeric,Format("Percent",10,2),Continuous,Formula(:weight/MeanWeight)); // Define New column with % in name 

dt << New Column("Test",Numeric,Format("Percent",10,2),Formula(Col Cumulative Sum(:Name("% of Total Weight")))); // Define Test Column that demonstrates the use of Name function that can capture the column name with % in it 

Hope this explains my suggestion a little better, if not kindly offer a little more detail so I can try and help 

Best
Uday
Aam_jmp
Level IV

Re: Comparing rows and columns with special characters

@uday_guntupalli Even though I cannot provide the table, a part of what I want to achieve is to be able to parse column names. I have made up data tables which look somewhat similar. I want the below code to work for this data.

 

 

Names Default To Here( 1 );
dt1 = data table( "Example1" );
dt2 = data table( "Example2" );
dt4 = dt2:Column 1 << get values();
a = n rows(dt2);
For(i=1,i<=a,i++,
Parse("dt1:" || dt4[i]);
);

 

uday_guntupalli
Level VIII

Re: Comparing rows and columns with special characters

@Aam_jmp

dt1 = data table( "Example1" );

dt2 = data table( "Example2" );

ColValuesEx2 = dt2:Column 1 << Get Values;

a = n rows(dt2);

Res= {};

For(i=1,i<=a,i++,
temp = Concat("dt1:",ColValuesEx2[i]);
Insert Into(Res,temp);
);

Show(Res);

Try this. The issue I see with what you were previously doing was, ColName does not refer to an actual column. When you try to scope into data table 2, you should refer to a column that exists in the data table. 

 

I used concatenate instead of Parse and I get the result you want .

 

image.png

 

 

Best
Uday
Aam_jmp
Level IV

Re: Comparing rows and columns with special characters

Why doesn't it give the output I want with using Parse even after I give the correct name of the column though? Is there a way I can parse special characters like % and ()? @uday_guntupalli

uday_guntupalli
Level VIII

Re: Comparing rows and columns with special characters

@Aam_jmp,
    If you look at the documentation of Parse() which you may find under Help => Scripting Index ==> Parse , 
Parse by its definition is expecting  a string, however you are passing 2 arguments in your implementation and expecting them to be concatenated. This is the reason I could see why it does not work even if you provide the correct name of column. Scripting Index is your friend and use it more and more to help yourself with the syntaxes and function definitions. 

Best
Uday
Aam_jmp
Level IV

Re: Comparing rows and columns with special characters

Uday, thanks for the help. I am teaching myself this part. However, I was trying to accomplish putting in spec limits to a data table using another data table. I can do this smoothly if the names of columns do not have special characters. However, I am unable to handle the special chars in my data tables. One approach I tried was to find the (%) in my column names and replace them with a space. Even though it worked out, I do not think that it is the best solution to my problem. I know that I can use an addin to add spec limits but it would be good to know how I can solve this issue with jsl. Thanks for any input you could provide on this. My code is:

dt1 = Data Table( "Example1" );
dt2 = Data Table( "Example2" );
a = N Rows( dt2 );
For( i = 1, i < a, i++,
	Eval(
		Substitute(
				Expr(
					__col__ << Set Property( "Spec Limits", {LSL( _LSL_ ), USL( _USL_ ), Target( _Target ), Show Limits( 1 )} );

				),
			Expr( __col__ ), Parse( "dt1:" || dt2:ColumnName[i] ),
			Expr( _LSL_ ), dt2:LSL[i],
			Expr( _USL_ ), dt2:USL[i],
			Expr( _Target ), dt2:Target[i], 

		)

	)
);

 

uday_guntupalli
Level VIII

Re: Comparing rows and columns with special characters

@Aam_jmp,
        Maybe this is a helpful post you can learn something from https://community.jmp.com/t5/Discussions/Spec-limits-issue/m-p/50166. 

        I am trying to understand reading through the thread what your actual question was ? It will probably help if you defined what your goal is - so the threads are easier to answer and will be beneficial for the community in general. 

Best
Uday