How to find the unique sums in the values 1,2,4,8,16, 32 I apologize but I'm not sure what you would even call this problem. I have some data that provide a numeric code for race as follows: 

hispanic(1) + american_indian_or_alaska_native(2) + asian(4) + black_or_african_american(8) + native_hawaiian_or_other_pacific_islander(16) + white(32)

So for example, a 5 represents a person who identifies as Asian and Hispanic (4 + 1), and a 25 represents a person who identifies as Pacific Islander, Black, and Hispanic (16 + 8 + 1). 

I am trying to write a program that will retrieve what races are present from the given number. I figure there must be an equation that can determine the combination without detailing every unique combination, but I might be wrong! I tried to think about using modulo but I didn't get very far. 

Thanks, and if you have suggestions for tags, please comment as I'm not sure where this fits into mathematics. 

*edit Thanks everyone! This really helped me to think about the problem and generate an efficient solution. Answering my question didn't depend on using SAS but here is the SAS code I ended up using, which I think shows intuitively how to solve the problem: 

data want; 
    set have; 

/* convert decimal to 6-place binary */
    eth_bin = put(ethnicity, binary6.);  

/* if 1st digit is 1 then race is present, and so on*/ 
    if substr(eth_bin, 1, 1) = 1 then white = "Yes"; 
    if substr(eth_bin, 2, 1) = 1 then pacific_islander = "Yes"; 
    if substr(eth_bin, 3, 1) = 1 then black = "Yes"; 
    if substr(eth_bin, 4, 1) = 1 then asian = "Yes"; 
    if substr(eth_bin, 5, 1) = 1 then american_indian = "Yes"; 
    if substr(eth_bin, 6, 1) = 1 then hispanic = "Yes"; 
run;
Notice that the numbers $1, 2, 4, 8, 16, 32$ are all perfect powers of $2$. This means that from any sum of them, the individual components can always be retrieved because there is a unique way to express a number as a binary number. One way to retrieve the racial info is keep dividing by $2$ and getting the remainder. Every remainder of $1$ indicates a certain race (depending on the stage of division). If the remainder is $0$, that race is not present. To elaborate, roughly you follow this algorithm:


Let $n$ be your number with the racial info.
While $n$ is non-zero, re-assign $n$ to $\lfloor \frac{n}{2} \rfloor$ and make a note of the remainder. If the remainder is $1$, then that race is present, where the race starts at Hispanic and so on.
When $n=0$ you are finished, there are no more races.


Update: Henning Makholm's suggestions to use bitwise operators is in fact a more elegant solution, programmatically, but may be harder to grasp intuitively.
hispanic(1)
american_indian_or_alaska_native(2)
asian(4)
black_or_african_american(8)   native_hawaiian_or_other_pacific_islander(16)
white(32)
An example (not an entire program, just a routine) for QB64:
[
IF (yourcode%% = 0) THEN
-->PRINT "no preference"
ELSE
-->FOR i%% = 0 TO 5
----->j%% = 2 ^ i%%
----->IF (j%% AND yourcode%%) THEN
-------->SELECT CASE j%%
----------->CASE 1: v\$ = "hisp"
----------->CASE 2: v\$ = "amer"
----------->CASE 4: v\$ = "asian"
----------->CASE 8: v\$ = "black"
----------->CASE 16: v\$ = "pacific"
----------->CASE 32: v\$ = "white"
-------->END SELECT
-------->PRINT v\$
----->END IF
-->NEXT 'i%%
END IF
]
You can abbreviate your categories or spell them out in full. All pertinent categories will be listed for a given code.