- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Comparision in Select Where () statement
Hi all,
I have extensively searched this website and I think it's an easy solution, but for some reason I cannot get it to work and I have been stuck with it for 2 days.
In the below script I ask the user which part of specific column he would like to select. For example where the column has the value 8. (the column can have values from 1 up to 8). That I would like to select the rows with this value in this column and create a new dt where I create specific graphs with only this subset of the datatable.
It creates the subset table with the name with the number I have filled in the text box. It shows me what number I have filled in i.e. XNo = "8"; But the Select where ( Column == XNO) does not work. It does not give me an error, it just does not select the specific rows or makes the graph. It makes a new data table with the same name as the datatable I refer to.
If I fill in Select where (column == "8") or Select where( column ==
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Comparision in Select Where () statement
Try converting XNo to number (Num(XNo) OR use number edit box. You might also have to modify your column reference a bit (add [] to comparison). Below is example using Big Class table, use values between 12-17 to test
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
col = Column(dt, "age");
col_name_list = dt << get column names(string);
rdata = New Window( "Which part do you want to check?",
<<modal,
<<return result,
X = Text Edit Box( "Which part?" ),
text box("Click OK to save"),
Button box("OK",
XNo = X << Get Text
),
Button Box ("Cancel");
);
Show(XNo); //Shows me the string that was given i.e. if I fill in 8 it shows me --> XNo = "8";
//Selected desired rows based on values on column
dt << Select Where(col[] == Num(XNo));
dt_subset = dt << Subset(Selected Rows);
dt << clear select;
If there are specific values allowed, you could also modify your selector to be something which only lets user pick specific ones BUT start by getting this version working and then consider those options.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Comparision in Select Where () statement
Try converting XNo to number (Num(XNo) OR use number edit box. You might also have to modify your column reference a bit (add [] to comparison). Below is example using Big Class table, use values between 12-17 to test
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
col = Column(dt, "age");
col_name_list = dt << get column names(string);
rdata = New Window( "Which part do you want to check?",
<<modal,
<<return result,
X = Text Edit Box( "Which part?" ),
text box("Click OK to save"),
Button box("OK",
XNo = X << Get Text
),
Button Box ("Cancel");
);
Show(XNo); //Shows me the string that was given i.e. if I fill in 8 it shows me --> XNo = "8";
//Selected desired rows based on values on column
dt << Select Where(col[] == Num(XNo));
dt_subset = dt << Subset(Selected Rows);
dt << clear select;
If there are specific values allowed, you could also modify your selector to be something which only lets user pick specific ones BUT start by getting this version working and then consider those options.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Comparision in Select Where () statement
This is not the solution specifically but I just found out that the column needs to be Ordinal (or atleast not be continuous). Now I just have to create it in such a way that I still get all my other columns instead of only the age column. I will update when I have the correct fix, but thanks for this. I knew it was something dumb that was not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Comparision in Select Where () statement
I have no idea why it didn't work before, because I have tried the Num() statement before and also the col[]. Maybe I didn't do them at the same time, I don't know, tried many iteration but it is working now. Even changing the column to continous is not necessary. Only thing that I haven't tried before which is in your script is the "Names Default to here(1);" line.