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

Scripting: How to get a Name object from a quoted string?

Assume I have the name of a table variable as a quoted string in a run-time variable. How do I get the table variable Name object from that?

I had this same issue with table columns which I was able to work around by getting a list of table Column Names and iterating through them until I found a Name object that matched the string. Unfortunately there doesn't appear to be a function that returns table variables so this method doesn't work.

Background:
The purpose of this is to have a reusable library that can embed formulas in columns. Since the reuse code doesn't know the Table Variable Names or Column Names, I need to pass them to my functions as string parameters. However, if I use the string variable when building the formula the result is a quoted string instead of a reference to the column or table variable.
1 ACCEPTED SOLUTION

Accepted Solutions
XanGregg
Staff

Re: Scripting: How to get a Name object from a quoted string?

You can get the table variable's value from the string with

x = Current Data Table() << Get Table Variable( "teacher" );

And you can get a column's value with

x = column("height")[ 1 ];

Expressions can be used for more complicated meta-programming (JSL that manipulates JSL), but since you're starting with a string it may be better to use Parse() and Eval(). For example, the following takes a function name string and treats it as a function name.

s = "sqrt"; x = Eval( Parse( s || "(2)" ));

View solution in original post

5 REPLIES 5
XanGregg
Staff

Re: Scripting: How to get a Name object from a quoted string?

You can get the table variable's value from the string with

x = Current Data Table() << Get Table Variable( "teacher" );

And you can get a column's value with

x = column("height")[ 1 ];

Expressions can be used for more complicated meta-programming (JSL that manipulates JSL), but since you're starting with a string it may be better to use Parse() and Eval(). For example, the following takes a function name string and treats it as a function name.

s = "sqrt"; x = Eval( Parse( s || "(2)" ));

Re: Scripting: How to get a Name object from a quoted string?

Parse() is the command I needed. If only I had known about it a week ago! :)

Thanks!

EDIT: I spoke a bit too soon. Parse() won't work if the table variable name contains parentheses. (For example, "Width (mm)") I'll have to think about this a bit more...


Message was edited by: DaveS

Re: Scripting: How to get a Name object from a quoted string?

I figured out something that works:

-----------------------------Script Start-----------------------------
Clear Globals();
Clear Log();

MyParse = Function(
{sName}, {Default Local},

ex = "Name(xxx)";
newStr = "\!"" || sName || "\!"";

retVal = Munger(ex, 0, "xxx", newStr);
retVal = Parse(retVal);
);

str = "Width (mm)";
name = MyParse(str);
show(name);
-----------------------------Script End-----------------------------

Obviously this is restricted to parsing those strings that are names. Thanks for the help!
XanGregg
Staff

Re: Scripting: How to get a Name object from a quoted string?

Thanks for sharing your results. I just realized there's also a JSL function called As Name() that converts a string to a name.

Re: Scripting: How to get a Name object from a quoted string?

I have a .doc file that contains Column names that needs to be used to create a Oneway graph. I load the document and try to parse the string to use in the expression :

----Script Code----
headers = load text file("headers.doc");
heads = parse(headers);

Oneway( Y(: heads //This is the variable that contains the headers
),
X( :blah ),
Means and Std Dev( 1 ),
Box Plots( 1 ),
Mean Lines( 1 ),
Mean Diamonds( 1 ),
Mean Error Bars( 1 ),
Std Dev Lines( 1 ),
Points Jittered( 1 ),
Points Spread( 1 )
)
);


My question is, what type of string can I pass into Parse() so that I can insert multiple names into the Y() argument? Do the names need to be semi-colon, space, carrige return, comma delimited? And can I iterate through each of the Names? Thanks.


Update: I found the Word function that takes a string and delimiter and returns a list of words. This is just waht I was looking for because I can iterate over all of the words generating Oneway graphs per word. Thanks SAS.

Message was edited by: KaptainKodie