BookmarkSubscribe
Choose Language Hide Translation Bar
dfmoore
Community Trekker

if missing, then fill in with previous value for multiple columns

I'm having trouble getting this logic correct and I'm not sure where I'm going wrong. I want to have a script where, if the operator name is row i is the same as the operator name in row (i-1), then if the measurement value in row i is missing, fill it in with the measurement value in row (i-1). I have several measurement values, so I'm searching across columns for any column with "Meas" in the name.

So far, I have the script below, but it just isn't working and I'm not sure why..

(also, I'm new to the forum. How do I get the code to maintain the formatting when I copy it in?)

dt = current data table();

for (j=1, j<= ncols(dt),j++,

    colname = Column ( j ) << getname();

    If( Contains( colname, "Meas") > 0,

        for (i = 2, i <= nrows(dt), i++,

            if(Column("OperatorName") == Column("OperatorName")[i-1],

                if (column(j) == isMissing(),

                    column(j) = column(j)[i-1]; // set equal to row above

                );

            );

        );

    );

);

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User ms
Super User

Re: if missing, then fill in with previous value for multiple columns

The only error I can find is how Is Missing() is used. Think of it as a function rather than a value.

If( Is Missing( Column( j )[i] ),...

0 Kudos
2 REPLIES 2
ms
Super User ms
Super User

Re: if missing, then fill in with previous value for multiple columns

The only error I can find is how Is Missing() is used. Think of it as a function rather than a value.

If( Is Missing( Column( j )[i] ),...

0 Kudos
dfmoore
Community Trekker

Re: if missing, then fill in with previous value for multiple columns

<< head slap >>

Duh...

Thanks!

Daniel

0 Kudos