Subscribe Bookmark RSS Feed

Subset Creation

Hi guys, I want to create a subset in JMP 8

This is my script that doen't work
ModeInput = "ABC";
CurrentTable = Current Data Table();
CurrentTable << Select Where(Mode == ModeInput);
SubsetTable = CurrentTable << subset(...

When the folowing script works
CurrentTable = Current Data Table();
CurrentTable << Select Where(Mode == "ABC");
SubsetTable = CurrentTable << subset(...

Could you point me to the mistake ???
Thanx.

Message was edited by: Evgy
10 REPLIES
CurrentTable << Select Where(Mode == ABC); //Got "" that dont work here
SubsetTable = CurrentTable << subset(...

Could you point me to the mistake ???
Thanx.

Message was edited by: Evgy

Message was edited by: Evgy
pmroz

Super User

Joined:

Jun 23, 2011

This is one of those "features" of JSL that drives me crazy.
 Why can't I use a variable in place of a string constant?



Anyway the way around it is to use eval(parse()).  Here's how:




style="font-size: 10pt; font-family: "Courier New"; color: black;">ModeInput

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"ABC"

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">CurrentTable

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">Current
Data
Table

style="font-size: 10pt; font-family: "Courier New"; color: black;">()

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">

 





style="font-size: 10pt; font-family: "Courier New"; color: black;">search_expr

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: purple;">"CurrentTable
<<
Select Where(Mode == \!""

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: navy;">||

style="font-size: 10pt; font-family: "Courier New"; color: black;">
ModeInput

style="font-size: 10pt; font-family: "Courier New"; color: navy;">||

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"\!")"

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">

 





style="font-size: 10pt; line-height: 115%; font-family: "Courier New"; color: rgb(0, 0, 221);">eval

style="font-size: 10pt; line-height: 115%; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; line-height: 115%; font-family: "Courier New"; color: rgb(0, 0, 221);">parse

style="font-size: 10pt; line-height: 115%; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; line-height: 115%; font-family: "Courier New"; color: black;">search_expr))

style="font-size: 10pt; line-height: 115%; font-family: "Courier New"; color: navy;">;






Regards,

Peter
mpb

Super User

Joined:

Jun 23, 2011

Peter I agree with you that it's frustrating to not be able to just do the obvious in this kind of situation, and I like your all purpose way of getting a working result for even complex situations. In this particular case I would probably opt for the "almost obvious" solution which does seem to work.

Michael

ModeInput = "ABC";
CurrentTable = Current Data Table();

CurrentTable << Select Where(Mode == eval(ModeInput))
Thank you both a lot !!!

I was getting realy frustrated of this...

:)
I got a folow up question:

I want to do a subset when my input is
ModeInput = {"A","B"}
A vector of two variables and I want to do subset for both together (Mode = "A" and Mode = "B")

How do I do this?
ms

Super User

Joined:

Jun 23, 2011

Try something like this:

Works great :)

Then I have another folow up question:

The "ModeInput" size is flexible and not always 2 , how can I do the same?

Thanks.
ms

Super User

Joined:

Jun 23, 2011

Try the function below. It parses a flexible "Or" string for row selection using the same method as above. There may a simpler way – one can definitely pick a simpler function name :-) – but this seems to work (JMP 9).

pmroz

Super User

Joined:

Jun 23, 2011

I had to build a complex SELECT statement in JMP, for several columns, where selections had been made by the user. I created a function called BUILD IN LIST, which is similar in function to an SQL IN LIST. See the example in the comments for help on usage. Very helpful to me!





style="font-size: 10pt; font-family: "Courier New"; color: green;">//---------------------------------------------------------------------------

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: green;">/*
Function Name   
build in list





style="font-size: 10pt; font-family: "Courier New"; color: green;">

 





style="font-size: 10pt; font-family: "Courier New"; color: green;">Description:
Extend a JSL
selection statement from a column name and





style="font-size: 10pt; font-family: "Courier New"; color: green;">
style="">           

style=""> 
list
of desired values to search for.
style=""> 
For
example





style="font-size: 10pt; font-family: "Courier New"; color: green;">

 





style="font-size: 10pt; font-family: "Courier New"; color: green;">build
in list(":some_column",
{"AAA", "BBB", "CCC"})





style="font-size: 10pt; font-family: "Courier New"; color: green;">

 





style="font-size: 10pt; font-family: "Courier New"; color: green;">will
return





style="font-size: 10pt; font-family: "Courier New"; color: green;">(:some_column
== "AAA"
| :some_column == "BBB" | :some_column == "CCC")





style="font-size: 10pt; font-family: "Courier New"; color: green;">

 





style="font-size: 10pt; font-family: "Courier New"; color: green;">If
the select statement is not
null, concatenate the new statement to the old one





style="font-size: 10pt; font-family: "Courier New"; color: green;">

 





style="font-size: 10pt; font-family: "Courier New"; color: green;">Arguments:





style="font-size: 10pt; font-family: "Courier New"; color: green;">col_name
style="">       
Column name, e.g. ":AGE"





style="font-size: 10pt; font-family: "Courier New"; color: green;">value_list
style="">     
List of values to search for





style="font-size: 10pt; font-family: "Courier New"; color: green;">join_operator
style="">  
How
to join the new statement to the old
one. 
"|" for OR,





style="font-size: 10pt; font-family: "Courier New"; color: green;">
style="">           

style="">    
and
"&" for AND





style="font-size: 10pt; font-family: "Courier New"; color: green;">select_string
style="">  
Existing
selection statement





style="font-size: 10pt; font-family: "Courier New"; color: green;">



Sample usage:

// Serial #

selection_string = "";

selection_string = build in list(":Serial", serial_list,
" & " , selection_string);



//------------------------------------------------------------------------------

// Label

selection_string = build in list(":Label", label_list, " & " ,
selection_string);



//------------------------------------------------------------------------------

// Gender

selection_string = build in list(":Gender", gender_list, " & "
, selection_string);




style="font-size: 10pt; font-family: "Courier New"; color: green;">*/

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">build
in list

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">Function

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: black;">
{col_name

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">
value_list

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">
join_operator

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">               
select_string}

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,





style="font-size: 10pt; font-family: "Courier New"; color: navy;">
style="">               

style="font-size: 10pt; font-family: "Courier New"; color: black;">{

style="font-size: 10pt; font-family: "Courier New"; color: black;">default
local}

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">

 





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">   
nl

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">nitems

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: black;">value_list)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">   

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">if

style="font-size: 10pt; font-family: "Courier New"; color: black;">
(nl

style="font-size: 10pt; font-family: "Courier New"; color: navy;">==

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: teal;">0

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">   

style="font-size: 10pt; font-family: "Courier New"; color: green;">//
then

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">       
in_list

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">""

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">           

style="font-size: 10pt; font-family: "Courier New"; color: green;">//
Return the null string

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">       

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">   

style="font-size: 10pt; font-family: "Courier New"; color: green;">//
else

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: green;">//
Loop over all values in the
list and create separate equals checks for each one.

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">       

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">for

style="font-size: 10pt; font-family: "Courier New"; color: black;">
(i

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: teal;">1

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">
i

style="font-size: 10pt; font-family: "Courier New"; color: navy;"><=

style="font-size: 10pt; font-family: "Courier New"; color: black;">
nl

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">
i

style="font-size: 10pt; font-family: "Courier New"; color: navy;">++,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">           

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">if

style="font-size: 10pt; font-family: "Courier New"; color: black;">
(i

style="font-size: 10pt; font-family: "Courier New"; color: navy;">==

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: teal;">1

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">           

style="font-size: 10pt; font-family: "Courier New"; color: green;">//
then

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">               
in_list

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"("

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: navy;">||

style="font-size: 10pt; font-family: "Courier New"; color: black;">
col_name

style="font-size: 10pt; font-family: "Courier New"; color: navy;">||

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"
==
\!""

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: navy;">||

style="font-size: 10pt; font-family: "Courier New"; color: black;">
value_list[i]

style="font-size: 10pt; font-family: "Courier New"; color: navy;">||

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"\!""

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">           

style="font-size: 10pt; font-family: "Courier New"; color: green;">//
else

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">               

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">               
in_list

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">
in_list

style="font-size: 10pt; font-family: "Courier New"; color: navy;">||

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"
| "

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: navy;">||

style="font-size: 10pt; font-family: "Courier New"; color: black;">
col_name

style="font-size: 10pt; font-family: "Courier New"; color: navy;">||

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"
==
\!""

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: navy;">||

style="font-size: 10pt; font-family: "Courier New"; color: black;">
value_list[i]

style="font-size: 10pt; font-family: "Courier New"; color: navy;">||

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">"\!""

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">           
)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">       
)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">       
in_list

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">
in_list

style="font-size: 10pt; font-family: "Courier New"; color: navy;">||

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">")"

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">

 





style="font-size: 10pt; font-family: "Courier New"; color: green;">//
Concatenate the new select
statement to the one fed in, if it's not null

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">       

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">if

style="font-size: 10pt; font-family: "Courier New"; color: black;">
(select_string

style="font-size: 10pt; font-family: "Courier New"; color: navy;">==

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: purple;">""

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">       

style="font-size: 10pt; font-family: "Courier New"; color: green;">//
then

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">           
select_string

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">
in_list

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">       

style="font-size: 10pt; font-family: "Courier New"; color: green;">//
else

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">           

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style=""> 

style="">          
select_string

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">
select_string

style="font-size: 10pt; font-family: "Courier New"; color: navy;">||

style="font-size: 10pt; font-family: "Courier New"; color: black;">
join_operator

style="font-size: 10pt; font-family: "Courier New"; color: navy;">||

style="font-size: 10pt; font-family: "Courier New"; color: black;">
in_list

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">       
)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">   
)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">   
select_string

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">   

style="font-size: 10pt; font-family: "Courier New"; color: green;">//
end build in list function

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">