cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
seburke89
Level III

Summarize Function with multiple by columns

All,

 

I'm trying to write a script that gets a count of observations, potentially by 1 or more columns (as determined by input from the user). I can get the script to work for one column, but not for two or more. How do I adjust the code in the by step of the summarize function to handle 1+ columns?

 

Below is a sample of script:

 

 

varName = VarList <<Get selected();
numCols = nitems(varName);
n = nrow(dt);

if(numCols == 0,
	//do one thing
,numCols>0,
	summarize(dt, cat = by(Column(dt,varName)),c=count);
	//do other things
);
	

 

 

 

Thanks!

Sarah

1 ACCEPTED SOLUTION

Accepted Solutions
Jeff_Perkinson
Community Manager Community Manager

Re: Summarize Function with multiple by columns

There's not quite enough information in your post to be sure I know what the problem is. It would be helpful to know what VarList is, and what the result of the <<Get Selected() message is. However, I suspect that VarList is a list of columns, liket this:

 

dt=open("$SAMPLE_DATA\Big Class.jmp");
varname={:age, :sex};

If so, then you need to put use Eval() around varname in the Summarize() function, like this:

 

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

varname = {:age, :sex};

//varName = VarList <<Get selected();
numCols = N Items( varName );
n = N Row( dt );

If(
	numCols == 0, 
	//do one thing
,
	numCols > 0,
		Summarize( dt, cat = by( Eval( varname ) ), c = count );
	//do other things
);
-Jeff

View solution in original post

2 REPLIES 2
Jeff_Perkinson
Community Manager Community Manager

Re: Summarize Function with multiple by columns

There's not quite enough information in your post to be sure I know what the problem is. It would be helpful to know what VarList is, and what the result of the <<Get Selected() message is. However, I suspect that VarList is a list of columns, liket this:

 

dt=open("$SAMPLE_DATA\Big Class.jmp");
varname={:age, :sex};

If so, then you need to put use Eval() around varname in the Summarize() function, like this:

 

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

varname = {:age, :sex};

//varName = VarList <<Get selected();
numCols = N Items( varName );
n = N Row( dt );

If(
	numCols == 0, 
	//do one thing
,
	numCols > 0,
		Summarize( dt, cat = by( Eval( varname ) ), c = count );
	//do other things
);
-Jeff
seburke89
Level III

Re: Summarize Function with multiple by columns

Sorry for the confusion on the varname variable. You've got it right - it's a list of column names that depend on input from the user from a GUI (that's the varList - a column list box). And you've solved my problem. Love it when it's a simple fix.

 

For my future knowledge then, anytime I want to reference data table column names in a function in JSL, things should work well with the eval() command around it? I always seem to have problems with that - especially when coding graphs.

 

Thanks much!

Sarah