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
GabeM27
Level II

Update multiple cells based on another cells value

When I execute the following it updates other cells that I did not create an if for. 

How can just update the ones I am calling out in the for row and if function? 

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Column( "NewAge", Character, Continuous );
dt << New Column( "NewAge2", Character, Continuous );
dt << New Column( "NewAge3", Character, Continuous );
For Each Row(
	If(
		dt:Age == 14,
			dt:NewAge = "Blah";
			dt:NewAge2 = "Blah2";
			dt:NewAge3 = "Blah3";

			dt:Age == 15;,
		dt:NewAge = "yay";
		dt:NewAge2 = "yay2";
		dt:NewAge3 = "yay3";

		dt:Age == 16;,
			dt:NewAge = "yo";
			dt:NewAge2 = "yo2";
			dt:NewAge3 = "yo3";
	),
	0
);
1 REPLY 1
Highlighted
txnelson
Super User

Re: Update multiple cells based on another cells value

  1. Your new columns are Character columns, therefore they can only have a Nominal Modeling Type.  
  2. You were using a semicolon ";" at the end of an IF() comparison, rather than a comma ",".  The scructure of an IF() function is:
    IF( comparison,
         // If True
         icalculation;
         calculation;
         ,
         // If not true
         comparison,
         // if True
         calculation;
         calculation;
         ,
         // Else
         calculation;
    ;
         
    Here is a rework of your code
  3. Names Default To Here( 1 );
    dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
    dt << New Column( "NewAge", Character );
    dt << New Column( "NewAge2", Character );
    dt << New Column( "NewAge3", Character );
    Current Data Table( dt );
    For Each Row(
    	If(
    		dt:Age == 14,
    			dt:NewAge = "Blah";
    			dt:NewAge2 = "Blah2";
    			dt:NewAge3 = "Blah3";, 
    
    		dt:Age == 15,
    			dt:NewAge = "yay";
    			dt:NewAge2 = "yay2";
    			dt:NewAge3 = "yay3";, 
    
    		dt:Age == 16,
    			dt:NewAge = "yo";
    			dt:NewAge2 = "yo2";
    			dt:NewAge3 = "yo3";,
    		"0"
    	)
    );
     
Jim
Article Labels

    There are no labels assigned to this post.