Page 1 of 1
Delete Empty Rows from a Table
Posted: Fri Mar 18, 2011 3:23 am
by Jun
Hi,
How do you remove empty rows from a table?
And how to you convert a table into a matrix?
I've tried using
if @isempty(sigbeta(!i,1)) = 1 then
sigbeta.deleterow(!i)
for the first part but it doesn't work.
Re: Delete Empty Rows from a Table
Posted: Fri Mar 18, 2011 8:38 am
by EViews Jason
When you say the first part is not working, do you mean the 'if' statement? This may be intentional, but the code you posted is only checking to see if the first cell in the row is empty. To check an entire row you will need to loop through the remaining cells in the row and verify they are also empty. I otherwise don't see anything wrong with your code.
NOTE: if the cell in the table only contains spaces, it may appear to be empty but it is not
There isn't an easy way to convert a table to a matrix. You would have to know ahead of time the size of the resulting matrix and then copy over 1 cell at a time.
Re: Delete Empty Rows from a Table
Posted: Fri Mar 18, 2011 7:02 pm
by Jun
Thanks Jason.
When I said it didn't work, I meant that the code runs properly but the rows don't get deleted. E.g.
[blank]
[blank]
ABC
[blank]
DEF
GHI
could end up with
[blank]
ABC
[blank]
DEF
GHI
Sometimes the blanks are gone but other times they remain. I suspect it's because when I use deleterow, the value of !i also changes so the next deleterow could be reading the wrong line. Is this the reason?
For the 2nd part, how do I calculate the no. of rows/members in a table then?
Re: Delete Empty Rows from a Table
Posted: Fri Mar 18, 2011 7:13 pm
by Jun
Oh Jason, I found anyway to do it. Thanks!
Re: Delete Empty Rows from a Table
Posted: Mon May 06, 2024 9:26 am
by CecileBF
Hi! Jun said he found a solution but did not mention which one.
So because it can be useful for other users, I post my own solution here.
The way I deal with a similar issue is by running the loop in reverse:
for !nbrow=@rows({%nametable}) to 2 step -1
if {%nametable}(!nbrow,1)="" 'here is my condition, but it can be wathever condition
{%nametable}.deleterow(!nbrow) 1
endif
next