cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Choose Language Hide Translation Bar
Onjai
Level III

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
ian_jmp
Staff

Re: Formula for Grouping months by season

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

View solution in original post

5 REPLIES 5
ian_jmp
Staff

Re: Formula for Grouping months by season

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

Onjai
Level III

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!

txnelson
Super User

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
pmroz
Super User

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",
				
			);
		)
	)
);
dale_lehman
Level VII

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)?