HI, I am a beginner at script writing in any language. I am currently meandering through what I thought would be a simple practice task. I am using JMP18. My goal is to automate a routine operation that I do with growing datasets over time. The routine operation is to first determine the time scale, and then show the change in data over that time scale for large datasets. The basic way I am approaching this is creating new columns to fill in all the initial data and using formulas on more columns to get differences. If someone has a better suggestion, I'd appreciate it. Below is where I am at:
Essentially, I have a set of data and I want to achieve the following.
1) I am looking to take the date and time columns, bring them together into a single column, and then I find the minimum, and use that to create a starting date. I can then subtract the times to see the difference in time between data. This was all simple enough with the formula() functions. Everything here works great.
2) I want to do something similar to several of the data columns, but I cannot do what I did before to find the initial value. The initial data is determined by the minimum time found in what I did before for every unique item in a third column (called Unique_Fruit in the code below). For the sake of this forum, for each unique_fruit, i want to create a column that contains the initial values of data for that fruit so i can then quickly calculate the changes from the actual data column.
My current JSL script is below. I have a dummy code formula where I haven't figured out what to do. It is the steps where I used the If function, found the times equal each other and set the value for only those cells. My original thought was to try using a for loop and iterate in the formula, but that did not seem to work.
DataTable = Current Data Table();
New Column( "Date Number Format", Numeric, "Continuous" );
For( i = 1, i <= N Rows( DataTable ), i++,
DataTable:Date Number Format[i] = Num( DataTable:Key_Date[i] );
);
New Column( "Time Number Format", Numeric, "Continuous" );
For( i = 1, i <= N Rows( DataTable ), i++,
DataTable:Time Number Format[i] = Num( DataTable:Key_Time[i] );
);
New Column( "Current_Time", Numeric, "Continuous" );
For( i = 1, i <= N Rows( DataTable ), i++,
DataTable:Current_Time[i] = DataTable:Date Number Format[i] + DataTable:Time Number Format[i];
);
New Column( "Unique_Fruit", Character, "Nominal" );
For( i = 1, i <= N Rows( DataTable ), i++,
DataTable:Unique_Fruit[i] = DataTable:Fruit[i] || "-" || DataTable:Type[i];
);
New Column( "Starting_Date_Number_Format", Numeric, "Continuous",
Formula( Col Minimum( :Current_Time, :Unique_Fruit ) )
);
New Column( "Minutes", Numeric, "Continuous",
Formula( Date Difference( :Starting_Date_Number_Format, :Current_Time, "Minute", "fractional" ) )
);
New Column( "Days", Numeric, "Continuous",
Formula( Date Difference( :Starting_Date_Number_Format, :Current_Time, "Day", "fractional" ) )
);
New Column( "Weeks", Numeric, "Continuous",
Formula( Date Difference( :Starting_Date_Number_Format, :Current_Time, "Week", "fractional" ) )
);
New Column( "Months", Numeric, "Continuous",
Formula( Date Difference( :Starting_Date_Number_Format, :Current_Time, "Month", "fractional" ) )
);
New Column( "Initial_Taste", Numeric, "Continuous",
Formula(
If( :Current_Time == :Starting_Date_Number_Format, :Key_Taste, . )
)
);
For( i = 1, i <= N Rows( DataTable ), i++,
If( DataTable:Current_Time[i] == DataTable:Starting_Date_Number_Format[i],
DataTable:Initial_Taste[i] = DataTable:Key_Taste[i];
);
);
New Column( "Delta_Taste", Numeric, "Continuous",
Formula( :Key_Taste - :Initial_Taste )
);
New Column( "%_Change_Taste", Numeric, "Continuous",
Formula( ( :Delta_Taste / :Initial_Taste ) * 100 + 100 )
);