Choose Language Hide Translation Bar
Highlighted

## Searching a value in a column- JSL

Hi All,

Can anyone help me with the search for a particular value in a column and try to find the count of that value with the overall count? In the below example, I am trying to search for value "1" in B column. I found 3 occurences in 10 instances so C is marked with 30%. Similarly for A=2, I found 4 occurence of "1" in 12 instances, so C is marked with 33%.

 A B C 1 1 30% 1 87 1 90 1 65 1 1 1 65 1 3 1 1 1 34 1 5 2 1 33% 2 5 2 2 2 47 2 1 2 54 2 1 2 85 2 1 2 1 2 22 2 21

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

## Re: Searching a value in a column- JSL

I think this should work:

col number(:b, :a, :b )/col number(:b, :a)

You need to take a look at the documentation on Col Number() in the Scripting Index

Help==>Scripting Index==>Col Number

Jim
10 REPLIES 10
Highlighted

## Re: Searching a value in a column- JSL

You can use the Tabulate Platform and specify the % Column Total as the statistic.

You can also create a new column and use the following formula to get the answer

``Col Number( :b, :b ) / Col Number( :b )``
Jim
Highlighted

## Re: Searching a value in a column- JSL

Thank you txnelson. What is :b represent? I am sorry , still new to this idea. I tried Tabulate also, I don't really understand the syntax which i should use as a grouping column?
Highlighted

## Re: Searching a value in a column- JSL

:b represents column "b", from the data table you listed in the original question.  The formula,

Col Number( :b, :b) / Col Num( :b )

is interpreted as:

the count of all of the values in column b, for the current rows value of column b, divided by the total count of the values for column b.

In the example data you provided, the calculation for the first row would be:

The count of values found in column b, that match the value for column b.  That is, the value of the first row for column b is "1", so it would count the number of "1"s found in column b, which is 8.  It would then divide by the total number of the values found in column b, which is 22.

Concerning the Tabulate Platform, what you would do, is to change the modeling type of column b to Nominal, so Tabulate will treat the column as a grouping column.  Then you would drag column b to the Drop Zone for Rows.  I will then list out each of the values found for column b.  By default, the statistic column that is listed is the count(N).  To change it to the Column %, you would just drag the Column % statistic to the "N" column, and it would replace the statistic with the column % Jim
Highlighted

## Re: Searching a value in a column- JSL

Thank you for the quick solution. Is there a way to segregate by column A. For example, instead of taking all 7 1's and 22 values together, can we do it by column A (10, 12) and getting the corresponding column % statistic?

Thanks.
Highlighted

## Re: Searching a value in a column- JSL

I think this should work:

col number(:b, :a, :b )/col number(:b, :a)

You need to take a look at the documentation on Col Number() in the Scripting Index

Help==>Scripting Index==>Col Number

Jim
Highlighted

## Re: Searching a value in a column- JSL

Wow. This is amazing. Thank you txnelson
Highlighted

## Re: Searching a value in a column- JSL

HI

I checked the Col Number. Is this what you mean? but it won't work.

Names Default To Here( 1 );
Open( "\$SAMPLE_DATA/Big Class.jmp" );
Col Number( :height,:height )/Col Num( :height )

Highlighted

## Re: Searching a value in a column- JSL

you misspelled "col number()" as "col num()"

``````Names Default To Here( 1 );
dt = Open( "\$SAMPLE_DATA/Big Class.jmp" );
dt << New Column( "thepercent",
formula( Col Number( :height, :height ) / Col Number( :height ) )
);``````
Jim
Highlighted

## Re: Searching a value in a column- JSL

Is there a way not to duplicate the values? As in, every 1's will be corresponding to the %. If I have multiple 1's in the each 1 will have 30% next to it. Can I make it appear once per Group A just like my example above? Helps me in the plotting and subsequent analysis.
Article Labels

There are no labels assigned to this post.