- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Formula for Grouping months by season
Take a look at the 'Match()' function in 'Help > Scripting Index'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Formula for Grouping months by season
Take a look at the 'Match()' function in 'Help > Scripting Index'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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",
);
)
)
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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)?