Desktop productivity for business analysts and programmers

Stacking columns

Reply
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

Grand Advisor
Posts: 10,210

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?

Grand Advisor
Posts: 9,571

Re: Stacking columns

It is easy for coding.



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

Ask a Question
Discussion stats
  • 2 replies
  • 359 views
  • 0 likes
  • 3 in conversation