cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar

Add Counter for Unique Cases in Groups

Hi all, 

How can I write an integer value counter to increment unique values in column B within group A, to do this?

StumptownSlash_0-1683660565893.png

Here is what I have tried so far:

 

dt_Table1 = Data Table("Table1");
dt_Table1 << New Column("Dataset", Numeric, "Nominal", Set Selected);

Sum1 = dt_Table1 << Summary(Group(:Group, :Date));
Sum2 = Sum1 << Summary(Group(:Group));
:N Rows << Set Name("N Datasets in Group");

dt_Table1 << Update(
	with(Data Table(Sum2)),
	Merge Same Name Columns
Match Flag(0),
	Suppress foruma evaluation(0),
	By Matching Columns(:Group = :Group),
	Drop multiples(1, 0),
	Include Nonmatches(0, 0),
	Preserve main table order(1)
);

dt = dt_Table1;
For(i = 1, i <= :N Rows(dt), i++,
	While(Group_Number = GetValue(:Group[i]),
		N == Get Value(dt, :N Datasets in Group[i]),
		For(j = 1, j <= N, j++,
			:Dataset << Set Value == (j),

		),
		Group_Number = Group_Number + 1,

	),

);

Outputs:

StumptownSlash_0-1683663388740.png

 

StumptownSlash_0-1683662459921.png

 

 

11 REPLIES 11
hogi
Level XIII

Re: Add Counter for Unique Cases in Groups

amazing!
Depending on the structure of the table, many orders of magnitude faster :)

 

but still far away from a solution for the right click New Formula Column menu :(

Names Default To Here( 1 );
dt = new table("Example",
New Column("A", character),
	New Column("B", character)
);
dt << add rows(20000);
for each row(
	:A = char(random integer(1,5));
	:B = char(random integer(1,1000));
);

t0 = hptime();
dt << New Column( "count",
	set each value(
		As Constant( Summarize( dt, bygroup = by( :a, :b) ) );
		N Items( Loc( bygroup[1], :a ) );
	)
);
(hptime() -t0)/1000000; //~ 1min

t0 = hptime();
dt << New Column("C", set each value(
	Col Sum(Row() == Col Min(Row(), :A, :B), :A);	
));
(hptime() -t0)/1000000; // < 1sec
hogi
Level XIII

Re: Add Counter for Unique Cases in Groups

happy news: JMP19 will provide Col N Unique()
https://community.jmp.com/t5/JMP-Wish-List/Col-N-Categories/idc-p/870972/highlight/true#M7292 
and it will be available via the new formula column menu:

hogi_0-1746284370642.png

 

Recommended Articles