Time for the big guns. Here's a script that should work. Basically the way it works is by iterating through all the rows and columns. If the next row has the same ID, it passes down the non-missing values to the next row. By the last row for a given ID, all non-missing values should be in that row. In the last step, you delete all the extra rows.
dt = Current Data Table();
dt << New Column( "Delete Later", character, formula( If( :ID[Row()] == :ID[Row() + 1], "Yes", "No" ) ) );
for(i=1,i<=N Row(dt),i++, //iterate through each row
//If next row has same ID, pass non-missing values down to next row
If(:Delete Later[i] == "Yes",
for(j=2,j<= (N Col(dt) - 1),j++, //iterate through each column (except ID and Delete Later)
//pass non-missing data down to next row
if(!isMissing(Column(dt,j)[i]), Column(dt,j)[i+1] = Column(dt,j)[i])
)
)
);
//Collapse all the extra rows
dt << Select Where(:Delete Later == "Yes") << Delete Rows();
This worked perfectly for your example. It should work for your table, though if you have millions of rows, it could take a good long while to finish. This script also assumes the column is named "ID" and all other columns should have non-missing values for only 1 row for each ID.
Starting table I used to test the script:
Final Table:
Script to recreate my starting table:
New Table( "ConsolidateTable",
Add Rows( 6 ),
New Column( "ID",
Character( 3 ),
"Nominal",
Set Values( {"1-A", "1-A", "1-A", "2-B", "2-B", "2-B"} ),
Set Display Width( 87 )
),
New Column( "Column 2",
Character( 16 ),
"Nominal",
Set Values( {"x", "", "", "y", "", ""} ),
Set Display Width( 87 )
),
New Column( "Column 3",
Character( 16 ),
"Nominal",
Set Values( {"y", "", "", "w", "", ""} ),
Set Display Width( 87 )
),
New Column( "Column 4",
Character( 16 ),
"Nominal",
Set Values( {"", "z", "", "", "t", ""} ),
Set Display Width( 87 )
),
New Column( "Column 5",
Character( 16 ),
"Nominal",
Set Values( {"", "q", "", "", "y", ""} ),
Set Display Width( 87 )
),
New Column( "Column 6",
Character( 16 ),
"Nominal",
Set Values( {"", "", "w", "", "", "q"} ),
Set Display Width( 87 )
),
New Column( "Column 7",
Character( 16 ),
"Nominal",
Set Values( {"", "", "w", "", "", "p"} ),
Set Display Width( 87 )
)
)
-- Cameron Willden