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

How to store the current filename as entries in a new variable

Let's imagine we open cities.jmp.

How could I get the name (pun intended) of 'cities' as entries for a new variable, say "MY_NAME".

So, the variable-to-be "MY_NAME" contains multiple instances of 'cities'. By nature, it has to be character, and "MY_NAME" is not a variable, but a constant.

 

Anyway, any idea how do do this?

I know there's a file function. GET NAME. But, I haven't made it so far to actually store the entries succesfully in MY_NAME.

Thanks in advance,

   still Newbie

1 ACCEPTED SOLUTION

Accepted Solutions
Jeff_Perkinson
Community Manager Community Manager

Re: How to store the current filename as entries in a new variable

I think we've got a confusion of terms. In a JMP data table we call them columns, not fields or variables (or constants). So, when you asked how to create a variable with 'cities' it was assumed you meant a JSL variable. 

 

Now, it seems you really want a column in your data table with the name of the data table in every row.

 

You've already seen, thanks to @txnelson, that the <<Get Name() message will give you the name of the data table.

 

Now you need to create a new column in your data table using the <<New Column() message. Within the New Column() you can use Set Values() to set the values for each row.

 

So, now we just need a list of values. We can get that using the Repeat() function.

 

The whole thing looks like this:

 

 

dt = Open( "$SAMPLE_DATA/Cities.jmp" );

dtname = dt << get name();

dtname_list = Repeat( {dtname}, N Row( dt ) );

dt << New Column( "Data Table Name", character, set values( dtname_list ) );

 

There are other ways of getting values into a column. We could use a formula where the "formula" is just a constant string but the syntax of that in JSL gets a bit confusing since we need to deal with when JSL expressions are evaluated (think Macro quoting in SAS; that's not where you'd want someone new to get started.)

 

Now, having said all of that, there aren't many cases where you need the name of the data table in all the rows of the data table as JMP will create columns like this in the cases where they are handy. For example, when concatenating data tables, there's an option to create a column with the name of the table that each row comes from.

 

JMPScreenSnapz010.png

 

Other table manipulations commands have similar options. So, perhaps you can tell us what you're trying to do that you feel you need this column and we may be able to help you even further.

-Jeff

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: How to story the current filename as entries in a new variable

This code places the data table name into a JSL variable

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/cities.jmp" );

MY_NAME = dt << get name;
Show( MY_NAME );
Jim
Newbie2Jumpie
Level IV

Re: How to story the current filename as entries in a new variable

I'm not at work right now...

That's all?
The new field MY_NAME will contain "cities" in every row?

Can't wait to get back to work :-)
Jeff_Perkinson
Community Manager Community Manager

Re: How to store the current filename as entries in a new variable

I think we've got a confusion of terms. In a JMP data table we call them columns, not fields or variables (or constants). So, when you asked how to create a variable with 'cities' it was assumed you meant a JSL variable. 

 

Now, it seems you really want a column in your data table with the name of the data table in every row.

 

You've already seen, thanks to @txnelson, that the <<Get Name() message will give you the name of the data table.

 

Now you need to create a new column in your data table using the <<New Column() message. Within the New Column() you can use Set Values() to set the values for each row.

 

So, now we just need a list of values. We can get that using the Repeat() function.

 

The whole thing looks like this:

 

 

dt = Open( "$SAMPLE_DATA/Cities.jmp" );

dtname = dt << get name();

dtname_list = Repeat( {dtname}, N Row( dt ) );

dt << New Column( "Data Table Name", character, set values( dtname_list ) );

 

There are other ways of getting values into a column. We could use a formula where the "formula" is just a constant string but the syntax of that in JSL gets a bit confusing since we need to deal with when JSL expressions are evaluated (think Macro quoting in SAS; that's not where you'd want someone new to get started.)

 

Now, having said all of that, there aren't many cases where you need the name of the data table in all the rows of the data table as JMP will create columns like this in the cases where they are handy. For example, when concatenating data tables, there's an option to create a column with the name of the table that each row comes from.

 

JMPScreenSnapz010.png

 

Other table manipulations commands have similar options. So, perhaps you can tell us what you're trying to do that you feel you need this column and we may be able to help you even further.

-Jeff
txnelson
Super User

Re: How to story the current filename as entries in a new variable

And to illustrate that in JMP there are typically many ways to approach ones solution, here is a variation on @Jeff_Perkinson example

dt = Open( "$SAMPLE_DATA/Cities.jmp" );

dtname = dt << get name();

dt << New Column( "Data Table Name", character, set each value( dtname ) );
Jim