World Statistics Day was yesterday, but we’re celebrating all week long! This celebration means acknowledging the impact statistics has on our world. Who is your favorite statistician? Share with us who they are and why they top your favorites list.
Choose Language Hide Translation Bar
Highlighted

## 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

## 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

Highlighted

## 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

## 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.