Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
Search instead for
Did you mean:
Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
How to reference variables in a formula in a FOR loop
Aug 13, 2016 7:56 AM(4419 views)
I tried asking this months ago but I was so lost that my explanation was incoherent. Then I got pulled away on assignment before being able to explain. So here is my hopefully better attempt to explain what I want and what isn't working.
What I'm doing: I'm creating a script that uses a large dataset that will constantly change, though the column names never will. I need to perform a variety of summaries and formulas. My strategy is to do some summary tables to determine which categories of data I have. The example below is a great, simplistic, example of what I'm trying to do. It uses the big class.jmp file and is looking for the sex categories. After it knows the categories, "M", "F" then it will create new columns for each variable category, in this case named :Example-F then :Example-M and within each new column there will be a formula that references other columns and does row calculations referencing the very new column being created.
My problem: I can't get the column references to work, in particular the variable that is calling upon the same column that the formula is being created under. See below
try(close(dt, No save));
try(close(dt_categories, No save));
try(close(dt_data, No save));
clear globals ();
dt = Open( "Path\big_class.jmp" );
//Creates list of gender and replaces names. No issues here.
//oldcol is created from the genderlist but represents the column names on the new dt_data and my formula will reference them. No issues here.
oldcol = column(genderlist);
//I have to name the new column different than the existing (old) column otherwise jmp will increment the names and it seems like it will really mess up my column name references. No issues here, I don't think.
newcolname = ("Example-"||genderlist);
//Next, I have tried creating the column first so the subsequent formula can reference an already existing column but I don't know if this is necessary.
newcol = dt_data << New Column(newcolname, numeric);
//Next line is a functional formula but doesn't use my variables as reference. You can use to see what I'm trying to do.
Thickey, that works perfect. Thank you! It's funny that I had tried the "asColumn" before but the documentation has it as "As Column" but it would always throw errors. Another cool trick you taught me was the summarize bit. @