cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
Kevin
Level I

set value to selected cells

Hello,

 

I am trying to select certain cells in data table and set value 2 to them, but it doesn't work. Can someone check my script to see what's wrong with it?

sdt << selectwhere(
	:Informat( "06/26/2018 16:49:00", "m/d/y h:m:s" ) <= :Time <= :Informat(
		"06/26/2018 16:54:00",
		"m/d/y h:m:s"
	)
);
selRows = sdt << getselectedRows;
As Column( sdt, "Status" )[selRows] = "2";
3 ACCEPTED SOLUTIONS

Accepted Solutions
mikedriscoll
Level VI

Re: set value to selected cells

I don't have data to run your scritpt on but I changed it around for my data and it worked ok (but I didn't use the informat() function).  Then I noticed you have a colon ":" before informat(), and the jsl editor does not show the hover text help for informat with the colon, but it does show it when I remove those colons. Try removing the two colons before the informat() and see if that helps. The colon is used to define a column variable. with syntax ":name" forces name to be evaluated as a data table column.  (edited to give a more accurate description, from JMP's website)

 

BTW thanks for the tip on the logic structure there. I had no idea I could do a x < y < z in one quick swoop. Usually it's x < y & y < z.

View solution in original post

pmroz
Super User

Re: set value to selected cells

If you use get rows where you can make sure that there are rows needing to be changed.  As mentioned remove the leading colon from Informat.  Change As Column to Column.

selrows = sdt << get rows where(
	Informat( "06/26/2018 16:49:00", "m/d/y h:m:s" ) <= :Time <= :Informat(
		"06/26/2018 16:54:00",
		"m/d/y h:m:s"
	)
);
if (nrows(selrows) > 0,
	Column( sdt, "Status" )[selRows] = "2";
);

 

View solution in original post

cwillden
Super User (Alumni)

Re: set value to selected cells

First, remove the colon before Informat().  That is telling JMP that Informat is a column name.  Start by taking those colons out.  You can also simplify your script like so:

sel rows = sdt << Get Rows Where(Informat("06/26/2018 16:49:00", "m/d/y h:m:s") <= :Time <= Informat("06/26/2018 16:54:00", "m/d/y h:m:s"));
sdt:Status[selRows]="2";

You also need to verify that Status is character column.  If it's numeric (even if the modeling type is nominal or ordinal), you need to remove the quotes around "2".

-- Cameron Willden

View solution in original post

6 REPLIES 6
mikedriscoll
Level VI

Re: set value to selected cells

I don't have data to run your scritpt on but I changed it around for my data and it worked ok (but I didn't use the informat() function).  Then I noticed you have a colon ":" before informat(), and the jsl editor does not show the hover text help for informat with the colon, but it does show it when I remove those colons. Try removing the two colons before the informat() and see if that helps. The colon is used to define a column variable. with syntax ":name" forces name to be evaluated as a data table column.  (edited to give a more accurate description, from JMP's website)

 

BTW thanks for the tip on the logic structure there. I had no idea I could do a x < y < z in one quick swoop. Usually it's x < y & y < z.

pmroz
Super User

Re: set value to selected cells

If you use get rows where you can make sure that there are rows needing to be changed.  As mentioned remove the leading colon from Informat.  Change As Column to Column.

selrows = sdt << get rows where(
	Informat( "06/26/2018 16:49:00", "m/d/y h:m:s" ) <= :Time <= :Informat(
		"06/26/2018 16:54:00",
		"m/d/y h:m:s"
	)
);
if (nrows(selrows) > 0,
	Column( sdt, "Status" )[selRows] = "2";
);

 

Kevin
Level I

Re: set value to selected cells

What's the difference of having if function here:

if (nrows(selrows) > 0,
	Column( sdt, "Status" )[selRows] = "2";
); 

 Also, what's the difference between ascolumn and column? 

 

Just try to understand the script

pmroz
Super User

Re: set value to selected cells

The if function insures that you only try to set Status values to 2 if there were any matches.

 

I'm not sure about the difference between Column and As Column.  Generally I just use Column.  If that doesn't work I try As Column. :)

cwillden
Super User (Alumni)

Re: set value to selected cells

First, remove the colon before Informat().  That is telling JMP that Informat is a column name.  Start by taking those colons out.  You can also simplify your script like so:

sel rows = sdt << Get Rows Where(Informat("06/26/2018 16:49:00", "m/d/y h:m:s") <= :Time <= Informat("06/26/2018 16:54:00", "m/d/y h:m:s"));
sdt:Status[selRows]="2";

You also need to verify that Status is character column.  If it's numeric (even if the modeling type is nominal or ordinal), you need to remove the quotes around "2".

-- Cameron Willden
Kevin
Level I

Re: set value to selected cells

It works, Thank you!