Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Highlighted

## If statement comparison statement

Hi! I am having trouble with my if statement below. I was wondering if you guys have any input. Thank you for your help!

``````Names Default To Here( 1 );
dt = Open(Example.jmp");
columnName = dt << Get Column Names (String);
ncol = 4;
Result = {"Continuous", "Continuous", "Categorical", "Continuous") // this is variable
ColumnData = {}
if ((Result == "Continuous"), // i am getting an error for this statement
ColumnData = Column(columnName[i])
// i want to store just column data and put it into a matrix, and perform operations on it               ); ``````

(Any ideas on how to better store the column data would also be helpful!)

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted  David_Burnham
Super User

## Re: If statement comparison statement

To get column values you can send the message Get Values to the column reference.  Based on your logic you are trying to only identify the numeric columns.  To do this you've defiend a list 'Results'  but the list should be terminated with a '}" whereas you have a closing parenthesis ')" (plus you need to terminate the assignment with a semicolon.  In fact, it is easier to add an additional keyword numeric to the Get Column Names message.  Here is an example:

``````dt = open("\$SAMPLE_DATA/Big Class.jmp");
cols = dt << get column names(string,numeric);
for (i=1,i<=nitems(cols),i++,
data = column(dt,cols[i])<<getValues;
show(cols[i],data)
);``````
-Dave
2 REPLIES 2
Highlighted  David_Burnham
Super User

## Re: If statement comparison statement

To get column values you can send the message Get Values to the column reference.  Based on your logic you are trying to only identify the numeric columns.  To do this you've defiend a list 'Results'  but the list should be terminated with a '}" whereas you have a closing parenthesis ')" (plus you need to terminate the assignment with a semicolon.  In fact, it is easier to add an additional keyword numeric to the Get Column Names message.  Here is an example:

``````dt = open("\$SAMPLE_DATA/Big Class.jmp");
cols = dt << get column names(string,numeric);
for (i=1,i<=nitems(cols),i++,
data = column(dt,cols[i])<<getValues;
show(cols[i],data)
);``````
-Dave
Highlighted

## Re: If statement comparison statement

If this case is as simple as getting all the NUMERIC columns, you can send the << Get As Matrix message to the data table.

Learn it once, use it forever!
Article Labels

There are no labels assigned to this post.