Delete Empty Rows from a Table

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

Jun
Posts: 12
Joined: Tue Mar 15, 2011 7:06 pm

Delete Empty Rows from a Table

Postby Jun » Fri Mar 18, 2011 3:23 am

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.

EViews Jason
EViews Developer
Posts: 870
Joined: Tue Sep 16, 2008 3:50 pm

Re: Delete Empty Rows from a Table

Postby EViews Jason » Fri Mar 18, 2011 8:38 am

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.

Jun
Posts: 12
Joined: Tue Mar 15, 2011 7:06 pm

Re: Delete Empty Rows from a Table

Postby Jun » Fri Mar 18, 2011 7:02 pm

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?

Jun
Posts: 12
Joined: Tue Mar 15, 2011 7:06 pm

Re: Delete Empty Rows from a Table

Postby Jun » Fri Mar 18, 2011 7:13 pm

Oh Jason, I found anyway to do it. Thanks!

CecileBF
Posts: 16
Joined: Mon Mar 27, 2023 8:54 am

Re: Delete Empty Rows from a Table

Postby CecileBF » Mon May 06, 2024 9:26 am

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


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests