BookmarkSubscribeRSS Feed
Kevin

Occasional Contributor

Joined:

Jun 28, 2018

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

Community Trekker

Joined:

Jun 23, 2011

Solution

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

Joined:

Jun 23, 2011

Solution

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";
);

 

cwillden

Community Trekker

Joined:

May 1, 2017

Solution

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
6 REPLIES
mikedriscoll

Community Trekker

Joined:

Jun 23, 2011

Solution

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

Joined:

Jun 23, 2011

Solution

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

Occasional Contributor

Joined:

Jun 28, 2018

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

Joined:

Jun 23, 2011

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

Community Trekker

Joined:

May 1, 2017

Solution

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

Occasional Contributor

Joined:

Jun 28, 2018

Re: set value to selected cells

It works, Thank you!