It’s World Statistics Day! To honor the theme of the day, the JMP User Community is having conversations about the importance of trust in statistics and data. And we want to hear from you! Tell us the steps you take to ensure that your data is trustworthy.
Choose Language Hide Translation Bar
Highlighted
Staff

## Re: Value selection and copy into new columns

I see this approach but there is a simpler way that does involve changing the selected row state. Instead of this:

``````SR1 = dt << Select Where(:Name("p-value (two-sided test) 2") <= 0.09) << Get Selected Rows; // You can edit this to conform to european convention of 0,09
dt << Clear Select; ``````

You can just use this:

``````SR1 = dt << Get Rows Where(:Name("p-value (two-sided test) 2") <= 0.09)
// You can edit this to conform to european convention of 0,09``````

This way you don't disturb the current row seletion.

Learn it once, use it forever!
Highlighted
Level III

## Re: Value selection and copy into new columns

@uday_guntupalli

I ran the script with my data (your version and with the exchange of the suggestion of @markbailey) and it works to create the columns and to get the selected data into the new column.

However, the last part (see below) to show the selected rows does not work. I adjusted it with a Select Where and Create Subset.

``````/* Step 3 */
// We already have the rows that meet the conditions
Show(SR1);
Show(SR2);
Show(SR3);
/* End of Step 3 */ ``````
``````/* Step 3 */
dt << Select Where (Name("p-value (two-sided test)2") <= 0.09);
dt << Subset( Output Table( "new_0,09" ), Selected Rows( 1 ), selected columns( 0 ) );
dt << Select Where (Name("p-value (two-sided test)2") <= 0.05);
dt << Subset( Output Table( "new_0,05" ), Selected Rows( 1 ), selected columns( 0 ) );
dt << Select Where (Name("p-value (two-sided test)2") <= 0.01);
dt << Subset( Output Table( "new_0,01" ), Selected Rows( 1 ), selected columns( 0 ) );
/* End of Step 3 */ ``` ```

Highlighted
Level III

Highlighted
Level III

## Re: Value selection and copy into new columns

Hey, here is the full version without the Show functions as those were not of any use in my case.

``````dt = Current Data Table(); // Assuming the data table is open

/* Step 1 - add 3 columns  */
dt << New Column("sign_0,09",Numeric,Continuous)
<< New Column("sign_0,05",Numeric,Continuous)
<< New Column("sign_0,01",Numeric,Continuous);

// Getting the values of column of interest
ColVals = dt:Name("p-value (two-sided test) 2") << Get Values;

// Set up a dummy matrix
Dummy = J(NRows(dt),1,.);

// All Rows
AllRows = Index(1,NRows(dt),1);

/* Step 2 - Select from the column based on conditions */
/* This could also be replaced by loop */
SR1 = dt << Get Rows Where(:Name("p-value (two-sided test) 2") <= 0.09);
//do not change "." to "," as the programme uses "." for background calculation
Dummy[SR1,0] = ColVals[SR1];

dt:Name("sign_0,09") << Set Values(Dummy);

// Re-initialize dummy matrix
Dummy = J(NRows(dt),1,.);

SR2 = dt << Get Rows Where(:Name("p-value (two-sided test) 2") <= 0.05);
Dummy[SR2,0] = ColVals[SR2];

dt:Name("sign_0,05") << Set Values(Dummy);

// Re-initialize dummy matrix
Dummy = J(NRows(dt),1,.);

SR3 = dt << Get Rows Where(:Name("p-value (two-sided test) 2") <= 0.01);
Dummy[SR3,0] = ColVals[SR3];

dt:Name("sign_0,01") << Set Values(Dummy);
/* End of Step 2 */

/* Step 3 */
dt << Select Where (Name("p-value (two-sided test)2") <= 0.09);
dt << Subset( Output Table( "new_0,09" ), Selected Rows( 1 ), selected columns( 0 ) );
dt << Select Where (Name("p-value (two-sided test)2") <= 0.05);
dt << Subset( Output Table( "new_0,05" ), Selected Rows( 1 ), selected columns( 0 ) );
dt << Select Where (Name("p-value (two-sided test)2") <= 0.01);
dt << Subset( Output Table( "new_0,01" ), Selected Rows( 1 ), selected columns( 0 ) );
/* End of Step 3 */``````

Highlighted
Level III

## Re: Value selection and copy into new columns

Hey, here is the full version without the Show functions as those were not of any use in my case.

``````dt = Current Data Table(); // Assuming the data table is open

/* Step 1 - add 3 columns  */
dt << New Column("sign_0,09",Numeric,Continuous)
<< New Column("sign_0,05",Numeric,Continuous)
<< New Column("sign_0,01",Numeric,Continuous);

// Getting the values of column of interest
ColVals = dt:Name("p-value (two-sided test) 2") << Get Values;

// Set up a dummy matrix
Dummy = J(NRows(dt),1,.);

// All Rows
AllRows = Index(1,NRows(dt),1);

/* Step 2 - Select from the column based on conditions */
/* This could also be replaced by loop */
SR1 = dt << Get Rows Where(:Name("p-value (two-sided test) 2") <= 0.09);
//do not change "." to "," as the programme uses "." for background calculation
Dummy[SR1,0] = ColVals[SR1];

dt:Name("sign_0,09") << Set Values(Dummy);

// Re-initialize dummy matrix
Dummy = J(NRows(dt),1,.);

SR2 = dt << Get Rows Where(:Name("p-value (two-sided test) 2") <= 0.05);
Dummy[SR2,0] = ColVals[SR2];

dt:Name("sign_0,05") << Set Values(Dummy);

// Re-initialize dummy matrix
Dummy = J(NRows(dt),1,.);

SR3 = dt << Get Rows Where(:Name("p-value (two-sided test) 2") <= 0.01);
Dummy[SR3,0] = ColVals[SR3];

dt:Name("sign_0,01") << Set Values(Dummy);
/* End of Step 2 */

/* Step 3 */
dt << Select Where (Name("p-value (two-sided test)2") <= 0.09);
dt << Subset( Output Table( "new_0,09" ), Selected Rows( 1 ), selected columns( 0 ) );
dt << Select Where (Name("p-value (two-sided test)2") <= 0.05);
dt << Subset( Output Table( "new_0,05" ), Selected Rows( 1 ), selected columns( 0 ) );
dt << Select Where (Name("p-value (two-sided test)2") <= 0.01);
dt << Subset( Output Table( "new_0,01" ), Selected Rows( 1 ), selected columns( 0 ) );
/* End of Step 3 */``````

Article Labels

There are no labels assigned to this post.