Subscribe Bookmark RSS Feed

Summary( ) Quesition


I have a problem when trying to call Summary(). I have a string containing the names of the columns that I want to create a summary table for, say var="height, weight". var may be different from data table to data table. I tried summary(sum(var)), but it didn't work. I wrote a loop that create a string var_expr=":height, :weight", but
summary(substitute("sum(x)",expr(x),var_expr)) doesn't do the job either...

Maybe I need to use column reference, but first I don't want to create many global variables, second I don't know in a priori how many columns are there. Is there any easy way to get around this?

Thank you!
You can use the Column function to reference a column based on a string value.

Here is some sample code that illustrates the use of the Summary and Summarize commands:

(scroll through to pages 185-188)
Hi Stig, thanks for your reply. I still ahve question about the Column function. If I have a list, say a={height, weight}, when I use Column(a), JMP returns Column("height"). Is there any way to make it return the reference for both columns at the same time without going through a loop?

The reason I'm asking this, is I want to do, for example

But the column names are provided by user in a variable, which I can only get through a list.

BTW, I have trouble viewing the reference you provided for summary command. I don't know why but the website doesn't load the zoomed in image...

Hi, sorry I didn't notice that you were processing a list of columns. Do you know the number of items in the list, or is it variable? Do you want to display the summary table to the user or are you just using it to calculate the column totals? Lastly, what is the reason for not wanting to use a loop? Sorry to answer your questions with a list of questions. Will take a look at this when I get a moment...
Here are a couple of examples that may help:

// example 1
dt = Open("$SAMPLE_DATA/Big");
lst = {"height","weight"};
c1 = lst[1];
c2 = lst[2];
Summary( sum( Column(c1),Column(c2) ) )

// example 2
dt = Open("$SAMPLE_DATA/Big");
lst = {"height","weight"};
Summary( Sum( Eval(lst) ) )

Message was edited by: _Stig_
Thank you! I think what I'm asking is answered by example 2. I'm writing a program which does the following job: suppose there are four columns in a data table, sex, height1, height2 and weight, the program will calculate sum(height1), sum(height2) and sum(weight) according to sex and then report sum(height1)/sum(wt) and sum(height2)/sum(wt) within each group (not for individual record, otherwise I think I can use the preselected role ). I'm trying to make the interface working for any data tables.

Now I'm trying to write it using both summary tables and matrices. Maybe the calculation can be done easily.

Thank you for your help!
Purely for reference, here is some example code that performs the task using the Summarize command and Associative Arrays