reshaping data

#1
I am trying to reshape data in SAS in a very specific way.

The data looks like:
ID Q1 Q2
491 0 0
491 0 1
1040 0 1
1040 1 0
1040 2 1

And, I want to transform the data to the following shape:
ID Q1A Q1B Q2A Q2B
491 0 0 0 1
1040 0 1 1 0
1040 0 2 1 1
1040 1 2 0 1

So, a pair of variables is created for each variable: Q1 = Q1A, Q1B and Q2 = Q2A, Q2B. For each ID, pairs are created for every combination and assigned to the new variables. For ID 1040, Q1 has three values 0,1,2 and so there are three pairs (0,1), (0,2), and (1,2).

I tried using proc transpose but I was not able to achieve this transformation. I think that this can be achieved via some (multi-dimensional) array processing ... but I don't know where to start.

Any pointers that can help me with this will be greatly appreciated.