cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Ckaiser
Level I

How to store unique column values as a list

I am trying to take a single column from my data table and store each unique value to a list.

 

Ex: 

column is named "Type" and the values in rows 1-6 are "A,B,C,A,B,C"

I currently have:

dtbl = Current Data Table();
newlist = column("Type") <<Getvalues();
Show(newlist);

 

which returns "A,B,C,A,B,C", but I am trying to get a list which would contain "A,B,C" instead. Any help would be appreciated (I am also new to JSL)

 

2 REPLIES 2
txnelson
Super User

Re: How to store unique column values as a list

Here are 2 ways of doing what you want

Names Default To Here( 1 );
dtbl = Current Data Table();

newList = Associative Array( dtbl:type << get values ) << get keys;

or

Names Default To Here( 1 );
dtbl = Current Data Table();

Summarize( dtbl, newlist = by( :Type ) );
Jim
jthi
Super User

Re: How to store unique column values as a list

Here is one more option using Summary. Getting unique values from :name column

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

dt_summary = Data Table("Big Class") << Summary(
	Group(:name),
	Freq("None"),
	Weight("None"),
	Link to original data table(0),
	private
);

uniq_vals = dt_summary[0,1];
Close(dt_summary, no save);

Do note that if you have numeric column and you want to get unique numbers, Summarize will return them as characters and not numbers.

-Jarmo