BookmarkSubscribeRSS Feed
Pratik612_
Calcite | Level 5

Hi Everyone,

I have a variable and has numeric values stored in it.I want to create the groups of those values whose sum is equal irrespective of number of values in each group. For eg,

T is a variable that has all the values:

T

1

2

3

4

5

6

7

Creating two groups of 14 each, the groups formed would be (1,3,4,6) and (2,5,7).

 

Kindly provide a generalized solution or idea because the variable actually has millions of rows.

 

Thanks.

 

5 REPLIES 5
Astounding
PROC Star
First, shorten the problem. The number of combinations to test is 2 raised to the power of # of observations. With millions of observations, you may not live long enough for a computer to perform all the calculations.

Questions: is T always an integer? Could two separate observations hold identical values for T? If so, would they count as 1 combination or 2?
Pratik612_
Calcite | Level 5
Thank you, for asking for clarification and making my post more precise.
Firstly, I want to group them into 10 groups and answering your qts T is not always an integer and can hold duplicate values, also they should be treated as different combinations.
Patrick
Opal | Level 21

@Pratik612_ 

"I want to group them into 10 groups"

This kind-of contradicts your initial statement where you're looking for combinations with the same sum.

 

With millions of values the number of possible combinations to test will exceed the computational power of your environment. 

It feels like you should get back to the drawing board and try to come up with an algorithm that gives you a desired result with a different/amended method which requires less computing.

 

You could also try and explain here in detail the underlying problem you want to solve, what you have and what you need. There might be other ways to approach things and someone here might have solved a similar problem before.

Ksharp
Super User

Yeah. It is impossible mission . There are too many solutions to suit your condition .

But if you have SAS/OR ,maybe give it a try (I also doubt due to big data).

Post is at OR forum and calling @RobPratt

Tom
Super User Tom
Super User

How precisely do they need to match?

Sort by descending value.

Assign the next value to the group with smaller current total.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 765 views
  • 0 likes
  • 5 in conversation