set value to selected cellsHello,
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";
Re: set value to selected cellsIt works, Thank you!
Re: set value to selected cellsThe 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. 
Re: set value to selected cellsWhat's the difference of having if function here:
if <SPAN class="token punctuation">(</SPAN>nrows<SPAN class="token punctuation">(</SPAN>selrows<SPAN class="token punctuation">)</SPAN> <SPAN class="token operator">></SPAN> <SPAN class="token number">0</SPAN><SPAN class="token punctuation">,</SPAN>
<SPAN class="token function">Column</SPAN><SPAN class="token punctuation">(</SPAN> sdt<SPAN class="token punctuation">,</SPAN> <SPAN class="token string">"Status"</SPAN> <SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">[</SPAN>selRows<SPAN class="token punctuation">]</SPAN> <SPAN class="token operator">=</SPAN> <SPAN class="token string">"2"</SPAN><SPAN class="token punctuation">;</SPAN>
<SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">;</SPAN>
Also, what's the difference between ascolumn and column?
Just try to understand the script
Re: set value to selected cellsFirst, 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".
Re: set value to selected cellsIf 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";
);
Re: set value to selected cellsI 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.