cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
See how to use JMP Live to centralize and share reports within groups. Webinar with Q&A April 4, 2pm ET.
Choose Language Hide Translation Bar
View Original Published Thread

How to convert the name of list into a string?

shaira
Level IV

Hi,

I have this script which checks if the list has duplicate elements, and if it does, it sends error message.

ColAgain=Function({main}, {duplicate},
					duplicate={};
					duplicate_r={};
					unique={};
					For (i=1,i<=Nitems(main),i++,
						If (Nrows(Loc(unique,main[i])) == 0,
							InsertInto (unique,main[i]),
							InsertInto (duplicate_r,main[i])
							);
						);
					For (i=1,i<=Nitems(duplicate_r),i++,
						If (Nrows(Loc(duplicate,duplicate_r[i])) == 0,
							InsertInto (duplicate,duplicate_r[i])
							);

						);
					if (Nitems(duplicate)>0,
						Write("ERROR. "||Char(main)||" has duplicates.");
						Caption("ERROR. "||Char(main)||" has duplicates. Check log.");
						For (i=1, i<=Nitems(duplicate), i++,
							 Show(duplicate[i]);
							);
					Throw();
						);
					duplicate;
				 );

Notice that I have this line:

Caption("ERROR. "||Char(main)||" has duplicates. Check log.");

What I want to appear is this:

"ERROR. GroupVar has duplicates. Check log."

However, this appears instead:

"ERROR. {"Element1", "Element2, "ElementN"} has duplicates. Check log."

Any ideas? Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Phil_Brown
Super User (Alumni)


Re: How to convert the name of list into a string?

Hi @shaira

I assume you want the VARIABLE name that is supplied as the function argument, to be displayed in the caption box? If so, this may work:

 

ColAgain = Function( {main},
	{duplicate},
	duplicate = {};
	duplicate_r = {};
	unique = {};
	For( i = 1, i <= N Items( main ), i++,
		If( N Rows( Loc( unique, main[i] ) ) == 0,
			Insert Into( unique, main[i] ),
			Insert Into( duplicate_r, main[i] )
		)
	);
	For( i = 1, i <= N Items( duplicate_r ), i++,
		If( N Rows( Loc( duplicate, duplicate_r[i] ) ) == 0,
			Insert Into( duplicate, duplicate_r[i] )
		);

	);
	If( N Items( duplicate ) > 0,
		Write( "ERROR. " || Char( main ) || " has duplicates." );
		Caption( "ERROR. " || Char( nameExpr(main) ) || " has duplicates. Check log." );
		For( i = 1, i <= N Items( duplicate ), i++,
			Show( duplicate[i] )
		);
		Throw();
	);
	duplicate;
);

groupVar = {1,2,3,3,5};
ColAgain( expr(groupVar) ); 

 

Note the use of Name Expr() in the Caption statement. Also, when calling the function, you have to wrap the argument with the keyword Expr()

PDB

View solution in original post

2 REPLIES 2
Phil_Brown
Super User (Alumni)


Re: How to convert the name of list into a string?

Hi @shaira

I assume you want the VARIABLE name that is supplied as the function argument, to be displayed in the caption box? If so, this may work:

 

ColAgain = Function( {main},
	{duplicate},
	duplicate = {};
	duplicate_r = {};
	unique = {};
	For( i = 1, i <= N Items( main ), i++,
		If( N Rows( Loc( unique, main[i] ) ) == 0,
			Insert Into( unique, main[i] ),
			Insert Into( duplicate_r, main[i] )
		)
	);
	For( i = 1, i <= N Items( duplicate_r ), i++,
		If( N Rows( Loc( duplicate, duplicate_r[i] ) ) == 0,
			Insert Into( duplicate, duplicate_r[i] )
		);

	);
	If( N Items( duplicate ) > 0,
		Write( "ERROR. " || Char( main ) || " has duplicates." );
		Caption( "ERROR. " || Char( nameExpr(main) ) || " has duplicates. Check log." );
		For( i = 1, i <= N Items( duplicate ), i++,
			Show( duplicate[i] )
		);
		Throw();
	);
	duplicate;
);

groupVar = {1,2,3,3,5};
ColAgain( expr(groupVar) ); 

 

Note the use of Name Expr() in the Caption statement. Also, when calling the function, you have to wrap the argument with the keyword Expr()

PDB
shaira
Level IV


Re: How to convert the name of list into a string?

Thanks! It works perfectly well.