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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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