cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
ambs
Level II

How to replace Missing Values w/ '0' using JSL

How do I replace Missing Values w/ '0' using JSL?

I can do this manually using 'Find and Replace All', but I need to incorporate it in a code that runs automatically everyday.

13 REPLIES 13
RaginCajun
Level I

Re: How to replace Missing Values w/ '0' using JSL

This works when I am running it from a scripting window using play button, but not within a debugger or launching it by autorun of the .jsl. 

 

dtLongestWaitStates << set name( "LongestWaitStates" );
dtLongestWaitStates = Current Data Table();
nc = dtLongestWaitStates << get column names( numeric );
For( i = 1, i <= N Items( nc ), i++,
	nc[i][dtLongestWaitStates << get rows where( Is Missing( nc[i][] ) )] = 0
);

 

RaginCajun

JMP13.2.1

jkwiggins
Level II

Re: How to replace Missing Values w/ '0' using JSL

Another way...

 

 

clsMat = dt << Get As Matrix( {"colA", "colB"} );

clsMat[Loc( Is Missing( clsMat ) )] = 0;

:colA << Set Values( clsRej[0, 1] );
:colB << Set Values( clsRej[0, 2] );

 

etc.

 

logical indexing is often faster than loops

Jason Wiggins
masakit
Level I

Re: How to replace Missing Values w/ '0' using JSL

cool! ... in the last 2 lines, clsRej should be replaced to clsMat, right?

meanwhile, do we have any similar solutions for character column?

msharp
Super User (Alumni)

Re: How to replace Missing Values w/ '0' using JSL

Since no one else answered, the solution is the same, just grab character columns instead and set the rows equal to the character you find fitting--"N/A" in the below case.

 

Just be careful, setting it =0 will change the column to numeric and will remove all the character data, however ="0" should be fine.

 

 

dt = Current Data Table();
nc = dt << get column names( Character );

For( i = 1, i <= N Items( nc ), i++,
  nc[i][dt << get rows where( Is Missing( nc[i][] ) )] = "N/A"
);

 

Recommended Articles