cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Use World Cup data to build models, explore spatial relationships, and create informative visualizations in JMP. Register. July 17, 2 pm US Eastern Time.
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

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

what is the sign function

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: what is the sign function

There doesn't appear to be a sign function in JSL.  Do you need a sign function?  Something that returns 1 for positive, 0 for zero, and -1 for negative?  Here's one solution:

/*

Function Name: sign

Description: Returns 1 if positive, 0 for zero, -1 for negative

Arguments:

one_number    Number to test

*/

sign = function( {one_number},

        {Default Local},

    sign_value = .;

    if (!is empty(one_number),

        if (one_number > 0,

            sign_value = 1,

            one_number == 0,

            sign_value = 0,

            one_number < 0,

            sign_value = -1

        );

    );

// Return the sign value

     sign_value;

);


Sample usage:


a = sign(47);

print(a);

b = sign(0);

print(b);

c = sign(-999999);

print(c);

Yields the following in the log window:

1

0

-1


View solution in original post

2 REPLIES 2
pmroz
Super User

Re: what is the sign function

There doesn't appear to be a sign function in JSL.  Do you need a sign function?  Something that returns 1 for positive, 0 for zero, and -1 for negative?  Here's one solution:

/*

Function Name: sign

Description: Returns 1 if positive, 0 for zero, -1 for negative

Arguments:

one_number    Number to test

*/

sign = function( {one_number},

        {Default Local},

    sign_value = .;

    if (!is empty(one_number),

        if (one_number > 0,

            sign_value = 1,

            one_number == 0,

            sign_value = 0,

            one_number < 0,

            sign_value = -1

        );

    );

// Return the sign value

     sign_value;

);


Sample usage:


a = sign(47);

print(a);

b = sign(0);

print(b);

c = sign(-999999);

print(c);

Yields the following in the log window:

1

0

-1


Re: what is the sign function

Thanks PMroz, works great.

Gene

Recommended Articles