BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar
gianpaolo
Community Trekker

help to Debug script

good morning,

someone can help me to debug this part of code

the code should open a dialog window for the current data table.

for the numeric columns selected by dialog,   the script should impute the empty cells with the mean of own column...

but dont understand why for some reason doesnt work

 

 

dt = Current Data Table();

cd = Column Dialog(

   Myregcol_x = Collist( " Select columns >>",MinCol (1) ),

   Hlist(""),

  );

 

regcol_x= cd["Myregcol_x"];

nitems = N Items( regcol_x );

colname_num={};

 

For( p = 1, p <= nitems, p++,

colname_num = regcol_x[p] << Get Data Type;

        if (colname_num == "Numeric",

                For( i = 1, i <= N items(regcol_x ), i++,

                        valuess = Column( regcol_x ) << get values( 1 );

                        valuess[Loc( Is Missing( valuess ) )] = Mean( valuess );

                        Column( regcol_x ) << setvalues( valuess, cc[i] );

                        );

             );

);

 

thanks in advance

Gianpaolo

Gianpaolo Polsinelli
0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: help to Debug script

You had a logic error in your use of 2 For Loops.  I simplified the script to where it works on one column at a time, which eliminated the second For Loop

Names Default To Here( 1 );
dt = Current Data Table();

cd = Column Dialog( Myregcol_x = Collist( " Select columns >>", MinCol( 1 ) ), Hlist( "" ), );

regcol_x = cd["Myregcol_x"];
nitems = N Items( regcol_x );
colname_num = {};

For( p = 1, p <= nitems, p++,
	colname_num = regcol_x[p] << Get Data Type;
	If( colname_num == "Numeric",
		valuess = Column( regcol_x[p] ) << get values;
		valuess[Loc( Is Missing( valuess ) )] = Mean( valuess );
		Column( regcol_x[p] ) << setvalues( valuess, cc[p] );
	);
);
Jim
2 REPLIES 2
txnelson
Super User

Re: help to Debug script

You had a logic error in your use of 2 For Loops.  I simplified the script to where it works on one column at a time, which eliminated the second For Loop

Names Default To Here( 1 );
dt = Current Data Table();

cd = Column Dialog( Myregcol_x = Collist( " Select columns >>", MinCol( 1 ) ), Hlist( "" ), );

regcol_x = cd["Myregcol_x"];
nitems = N Items( regcol_x );
colname_num = {};

For( p = 1, p <= nitems, p++,
	colname_num = regcol_x[p] << Get Data Type;
	If( colname_num == "Numeric",
		valuess = Column( regcol_x[p] ) << get values;
		valuess[Loc( Is Missing( valuess ) )] = Mean( valuess );
		Column( regcol_x[p] ) << setvalues( valuess, cc[p] );
	);
);
Jim
gianpaolo
Community Trekker

Re: help to Debug script

Fantastic!!!! , thanks a Lot

Gianpaolo Polsinelli