Desktop productivity for business analysts and programmers

Stacking columns

New Contributor vem
New Contributor
Posts: 4

Stacking columns

[ Edited ]

Hi Good day!

I am trying to stack 26 columns into one column in sas enterprise guide....and its ending up with the error "THE ID VALUE 'STACKEDVALUES' OCCURS TWICE IN THE INPUT DATA SET".I wanted the repeated values as present in the data base (don't want to elminate the duplicates).

Any help ....

for example :

mem_id  type_1  type_2

a001        x            a

a002        y            b

a003        z            c

and stack expecting like

mem_id name      type

a001     type_1    x

a001     type_2    a

a002     type_1    y

a002     type_2   b

a003     type_1   z

a003     type_1   c

Super User
Posts: 13,942

Re: Stacking columns

Please describe in considerable detail exactly how you are attempting to stack things. Code generated would be best.

You might also have to show some example of your current data and what you want it to look like afterwards.


Are you attempting to put multiple values into a single variable of one observation or create additional observations, one per variable?

Super User
Posts: 10,859

Re: Stacking columns

It is easy for coding.

data have;
input (mem_id  type_1  type_2) ($);
a001        x            a
a002        y            b
a003        z            c
data want;
 set have;
 array x{*} $ type_:;
 do i=1 to dim(x);
 drop i type_:;

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation