Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
lwx228
Level VII

How to implement filter after matching with JSL without auxiliary columns?

Hello, everyone!

Open two files "Pizza Responses" and B.Follow the following two steps:

d1 = Open( "$SAMPLE_DATA/Pizza Responses.jmp" );
d2 = Open( "$SAMPLE_DATA/Pizza Subjects.jmp" );

1. Add "Gender" columns from file "Pizza Subjects" match through column 1 in "Pizza Responses".
2. Select column "Gender" as "M" and column "Choice" as "TrimPepperjack".
How Can use JSL to realize filtering after matching without adding auxiliary columns to A file?

 

Thanks!

2019-11-06_18-42.png

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: How to implement filter after matching with JSL without auxiliary columns?

@lwx228 ,

Here is a pretty brut force way to do this

Names Default To Here( 1 );

d1 = Open( "$SAMPLE_DATA/Pizza Responses.jmp" );
d2 = Open( "$SAMPLE_DATA/Pizza Subjects.jmp" );

// Get subject IDs for all male subjects
males = d2 << get rows where( :gender == "M" );

maleSubjects = {};
For( i = 1, i <= N Rows( males ), i++,
	Insert Into( maleSubjects, Char( d2:subject[males[i]] ) )
);

theRows = d1 << get rows where(
	:Choice == "TrimPepperjack" & Contains( maleSubjects, Char( :Subject ) )
);

dSubset = d1 << subset(
	selected columns( 0 ),
	Rows( theRows ),
	output Table( "text" )
);

I am also going to add, that I think you need to be working through these items yourself, before you throw them to the Discussion forum.  You have been very active on the forum with your questions, and the knowledge gained from the user responses, needs to be folded into your independent efforts.  

Jim

View solution in original post

6 REPLIES 6
Highlighted
txnelson
Super User

Re: How to implement filter after matching with JSL without auxiliary columns?

@lwx228 ,

Here is a pretty brut force way to do this

Names Default To Here( 1 );

d1 = Open( "$SAMPLE_DATA/Pizza Responses.jmp" );
d2 = Open( "$SAMPLE_DATA/Pizza Subjects.jmp" );

// Get subject IDs for all male subjects
males = d2 << get rows where( :gender == "M" );

maleSubjects = {};
For( i = 1, i <= N Rows( males ), i++,
	Insert Into( maleSubjects, Char( d2:subject[males[i]] ) )
);

theRows = d1 << get rows where(
	:Choice == "TrimPepperjack" & Contains( maleSubjects, Char( :Subject ) )
);

dSubset = d1 << subset(
	selected columns( 0 ),
	Rows( theRows ),
	output Table( "text" )
);

I am also going to add, that I think you need to be working through these items yourself, before you throw them to the Discussion forum.  You have been very active on the forum with your questions, and the knowledge gained from the user responses, needs to be folded into your independent efforts.  

Jim

View solution in original post

Highlighted
lwx228
Level VII

Re: How to implement filter after matching with JSL without auxiliary columns?

Thank JIM! Thank you for helping me all the time.



Since I used to use VBA all the time, these problems can be solved easily with a dictionary.
But there doesn't seem to be a similar way to write data into a table with JMP.

I also searched in the JMP help file and failed to find a similar method, mainly due to my poor English foundation.
The English of my these questions is I use translation software to make.So many expressions are not rigorous.Please forgive me!

For a questions like this, because This file has many lines, I don't want to add a column to the table, than instead run it in memory and output it directly.
Thanks again, JIM, and thanks again to all the Experts in the Discussions for their help!

Highlighted
lwx228
Level VII

Re: How to implement filter after matching with JSL without auxiliary columns?

Line by line cycle is a pretty brut force way.
In this way, if there are not many targets to be screened, it can be carried out in three steps:
1. Select "TrimPepperjack" to produce subset.
2. Match "M" in the subset.
3. Select "M" again.
Than It's a lot less computation burden.

So I can do it on my own.Thanks!

Highlighted
txnelson
Super User

Re: How to implement filter after matching with JSL without auxiliary columns?

You may also want to look into using a virtual Join, which will relate data tables without actually joining them. That would allow you to code your script as if the column existed within your data table, even though it does not.
Jim
Highlighted
lwx228
Level VII

Re: How to implement filter after matching with JSL without auxiliary columns?

Thank Jim!

 

OK.I found it in the help file. I need to learn.

This is expected to be faster?

 

2019-11-07_19-29.png

Highlighted
txnelson
Super User

Re: How to implement filter after matching with JSL without auxiliary columns?

It should be faster.....

Jim
Article Labels

    There are no labels assigned to this post.