BookmarkSubscribeRSS Feed
pscott
Calcite | Level 5

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

6 REPLIES 6
ballardw
Super User

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        <>

pscott
Calcite | Level 5

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

ballardw
Super User

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.

pscott
Calcite | Level 5

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
ballardw
Super User

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.

LinusH
Tourmaline | Level 20

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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1443 views
  • 1 like
  • 3 in conversation