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!
Choose Language Hide Translation Bar
Highlighted
debraj_guha
Level II

Using If statement while creating a table

Hello all,

I am trying to create a table with an If () to set values to the cells. As shown in the piece of representative code below, I am using a variable, Counter, to point to a row in a separate summary table (dt) and use that as the values for the new table. However, I want to make sure that the code does not break if Counter=0, i.e. if the summary table where I am pulling the data from, does not contain the rows I want. I have used the method below but it doesn't work. I have tried placing the If () in various locations and haven't been successful either. Please suggest some ways if anyone has faced this issue before.

 

Thanks

D

 

New Column( "Parameters",

Numeric,

"Continuous",

Set Values( If(Counter>0,{dt:Col1[Counter], dt:Col2[Counter], dt:Col3[Counter]}, {N/A, N/A, N/A})

               )

          )

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: Using If statement while creating a table

The list values are not going to be processed.  Therefore, the following will get done what I think you are trying to do.

names default to here(1);
dt=current data table();

counter=1;

theList = {};

if(counter>0,
	insert into(theList, char(dt:col3[counter]));
	insert into(theList, char(dt:col2[counter]));
	insert into(theList, char(dt:col1[counter])),
	theList = {"N/A", "N/A", "N/A"};
);

dtx=new table("test",
	new column("Parameters", character,set values(eval(theList)))
);
Jim

View solution in original post

2 REPLIES 2
Highlighted
txnelson
Super User

Re: Using If statement while creating a table

The list values are not going to be processed.  Therefore, the following will get done what I think you are trying to do.

names default to here(1);
dt=current data table();

counter=1;

theList = {};

if(counter>0,
	insert into(theList, char(dt:col3[counter]));
	insert into(theList, char(dt:col2[counter]));
	insert into(theList, char(dt:col1[counter])),
	theList = {"N/A", "N/A", "N/A"};
);

dtx=new table("test",
	new column("Parameters", character,set values(eval(theList)))
);
Jim

View solution in original post

Highlighted
debraj_guha
Level II

Re: Using If statement while creating a table

Thanks Jim. This did what I was trying to do.

Regards
D