Community Trekker

Joined:

Jul 12, 2017

## Formula for Grouping months by season

Hi,

I thought this was a rather simple formula to create, but found myself receiving formatting errors.

I have a column, character type, that contains months (October, November, December, and so on...).  I created a new column called "season" and wrote an IF(Contains(...formula to claasifiy if the month is October Then = fall,  and so on through the list creating the 4 categories (summer, winter, spring, fall).  However, the CONTAINS will not take the OR.

i.e.

If(Contains(:month, "October" | "November"), "fall", Empty())

What am I missing?  Any assistance would be appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions

Staff

Joined:

Jun 23, 2011

Solution

## Re: Formula for Grouping months by season

Take a look at the 'Match()' function in 'Help > Scripting Index'.

5 REPLIES

Staff

Joined:

Jun 23, 2011

Solution

## Re: Formula for Grouping months by season

Take a look at the 'Match()' function in 'Help > Scripting Index'.

Community Trekker

Joined:

Jul 12, 2017

## Re: Formula for Grouping months by season

Ian,

Worked fine!  Nice and clean.

Thank you and the rest of the fine folks in the jmp community.

Cheers!

Super User

Joined:

Jun 22, 2012

## Re: Formula for Grouping months by season

``If(Contains(:month, "October") | Contains(:month, "November"), "fall", "")``

The above is the correct syntax for the approach you were taking.  However, Ian's approach is a more readable, and therefore more proper method

Jim

Super User

Joined:

Jun 23, 2011

## Re: Formula for Grouping months by season

You can search a column for a list of values.  Here's a formula that uses that approach.

``````dt = New Table( "test", Add Rows( 12 ),
New Column( "Month", Character, "Nominal",
Set Values(
{"January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"}
)
),
New Column( "Season",
Character,
"Nominal",
Formula(
spring_list = {"March", "April", "May"};
summer_list = {"June", "July", "August"};
fall_list   = {"September", "October", "November"};
winter_list = {"December", "January", "February"};
If( Contains( spring_list, :Month ), "Spring",
Contains( summer_list, :Month ), "Summer",
Contains( fall_list,   :Month ), "Fall",
Contains( winter_list, :Month ), "Winter",

);
)
)
);``````

Community Trekker

Joined:

Jan 29, 2015

## Re: Formula for Grouping months by season

As Jim points out, the sytax requires that the OR statement repeat the column = within the statement.  Match does work better, but why not just use the column Recode utility (which will produce the match formula)?