Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
lwx228
Level VII

Is there efficient code that implements multiple columns of all non-null rows?

I can only do it this way, if it's more than 100 columns it's too inefficient.

Thanks!

2019-12-20_21-47.png

dt=Open("$SAMPLE_DATA\Missing Data Pattern.jmp");
dt << Select Where(
	abs(As Column(1))>=0&abs(As Column(2))>=0&abs(As Column(3))>=0&abs(As Column(4))>=0
);
Wait( 0 );
d3 = dt << Subset( Output Table( "text" ), Selected Rows( 1 ), selected columns( 0 ) );
Wait( 0 );
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
cwillden
Super User

Re: Is there efficient code that implements multiple columns of all non-null rows?

You could do something like this:

dt = Current Data Table();

//Get list of current names:
cols = dt << Get Column Names();

//Build a string iteratively to select non-missing from each column
str = "dt << Select Where(!Is Missing(:Name(\!""||char(cols[1])||"\!")) ";
for(i = 2, i<= N Items(cols), i++,
	str = str||"& !Is Missing(:Name(\!""||char(cols[i])||"\!"))"
);
str = str ||")";

//parse and evaluate the string
eval(parse(str));
-- Cameron Willden

View solution in original post

1 REPLY 1
Highlighted
cwillden
Super User

Re: Is there efficient code that implements multiple columns of all non-null rows?

You could do something like this:

dt = Current Data Table();

//Get list of current names:
cols = dt << Get Column Names();

//Build a string iteratively to select non-missing from each column
str = "dt << Select Where(!Is Missing(:Name(\!""||char(cols[1])||"\!")) ";
for(i = 2, i<= N Items(cols), i++,
	str = str||"& !Is Missing(:Name(\!""||char(cols[i])||"\!"))"
);
str = str ||")";

//parse and evaluate the string
eval(parse(str));
-- Cameron Willden

View solution in original post

Article Labels

    There are no labels assigned to this post.