I'm Confused About VariablesI'm having a conceptual problem figuring out how local variables work. I'll simplify the issue to focus in on what is confusing to me.
I create a local variable, say t0, with a value of 5. Then I write a column formula to increment this value by 1... either t0=t0+1 or t0+=1 (it doesn't seem to matter), the result that I expected was that when JMP evaluated each cell in the column, it would increment the variable so I'd get 6, 7, 8, etc as I moved down the column. Instead, I get a column of 6's. So the formula is not incrementing the variable.
Can someone explain to me what I'm not understanding about how JMP handles local variables? Also, since my approach doesn't work is there another way to increment a variable? I can do it with Lag but that seems needlessly complex for something so simple.
Also, I'm not clear on the distinction between local variables, table variables, and parameters.
Thanks in advance for all help provided.
Automation and ScriptingRe: I'm Confused About VariablesYou might be interested in the Row() function inside of a column formula -- it returns the current row that the formula is being run against. As for variables and scoping -- it is usually best to be explicit about variable scopes. Thus to use a global counter, do ::t0 += 1 -- the double colon explicitly scopes the name to the global namespace. If you want a local name, explicitly scope it, i.e., local:t0 There is also the Here namespace, and again it is best to be explicit in scoping. I recommend being explicit as JMP is buggy and will not always adhere to the stated scoping rules.
Re: I'm Confused About VariablesI guess that you wrote something like the following as a column formula:
Local({t0 = 5}, t0 = t0 + 1)
And you expect that the initial assignment
t0 = 5
only occurs once when the data table evaluate a column, cell by cell from top to bottom.
You have seen that is not happening. What you see is the assignment occurs every time when a cell is evaluated. If you have SAS programming experience, you might be looking for something similar to RETAIN statement in SAS. I am not aware of such thing exists in JMP's scripting language.
But I had the similar need to do calculations that need to retrieve results in previous calculations.
If the result is intermediate and temporary, I will store the result in a separate column. If the result is just a value in previous cell in the same column, I will just refer to the previous cell. Either way, you may need to use the Row() function that @ErraticAttack mentioned.
I attach an example to illustrate.