Help using Base SAS procedures

Transposing

Reply
Occasional Contributor
Posts: 5

Transposing

Hello,

 

I have sorta a complex transpose I need to do I neet to take something like this

 

Stone1_row_1Stone1_row_2Stone1_row_3Stone2_row1Stone2_row2Stone2_row3

 

and make it look like this

 

Stone1_row_1Stone1_row_2Stone1_row_3
Stone2_row1Stone2_row2

Stone2_row3

 

Does anybody know an easy way to do this.

 

Thanks for the help,

Preston

Super User
Posts: 10,500

Re: Transposing

Are those VALUES or Variables?

Do you want this in a report or a data set? Since SAS datasets only have one variable per column then that request may not make sense.

What will you be doing with the result if you want a data set?

From what you show you may be better served for many purposes with a set structured as

Stone Row Value

1        1        <whatever is currently in stone1_row_1>

1         2        <next value>

1         3        <next value>

2         1       <>

2         2       <>

2         3        <>

Occasional Contributor
Posts: 5

Re: Transposing

Those are values, and I would like it in a data set. I would like to have the rows horizontal and the stones verticle.

 

Stone_nbr   row1   row2   row3 

1                    3         4         5  

1                    2         2         2

1

2

2

2

Super User
Posts: 10,500

Re: Transposing

What are your variable names? Actual example data helps things go better. This link https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show you how to create a data step that you can post here to create a few rows of data.

Occasional Contributor
Posts: 5

Re: Transposing

Im sorry but because of security reasons I cant post exactly what the data looks like but I hope this helps. The data looks something like this;

 

DWIDStone1_row_1Stone1_row_2Stone1_row_3Stone2_row1Stone2_row2Stone2_row3
1136399
2233487
3357384
4463773

 

And I would like it to look like this 

 

DWIDStone_NBRRow_1Row_2Row_3
11136
12399
21233
22487
31357
32384
41463
42773
Super User
Posts: 10,500

Re: Transposing

This works for your example data:

data want (keep=dwid stone_nbr Row_1-Row_3 );
   set have;
   array t {2,3} stone1: stone2:;
   array r {3} row_1 row_2 row_3;
   do stone_nbr= 1 to 2;
      do row= 1 to 3;
        r[row] = t[stone_nbr,row];
      end;
      output;
   end;
run;

 

Note that your previous answer to my question about variables versus values wasn't quite correct. You posted variable names, not values.

Super User
Posts: 5,256

Re: Transposing

I don't know anything of your requirement and real data - but IMO most scenarios benefit from even transpose your Row variables to rows:

DWID - Stone_NBR - Row_NBR - Row_Val (whatever that is)

 

 

Data never sleeps
Ask a Question
Discussion stats
  • 6 replies
  • 333 views
  • 1 like
  • 3 in conversation