BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PauloC
Fluorite | Level 6

Hello Experts,

I am a beginner of SAS and need your kind help to find the best way to transpose one table . Any advice will be greatly appreciated.

I have a sample data set as attachment where you can see what i want to do: Thank you very much for your time and help.

ExEx

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You can probably get there by using two PROC TRANSPOSE steps. First to convert your current wide struction into a tall structure.  Then a second one to convert it back into the even wider version you want.

proc transpose data=have out=tall;
  by p;
run;

proc transpose data=tall out=wide(drop=_name_) delim=_;
  id _name_ p ;
  var col1;
run;

But why do you think that is going to help you?

For most purposes the TALL structure is probably better. Or even your original semi-wide structure.

View solution in original post

2 REPLIES 2
Reeza
Super User

First transpose it to a long format and then you can transpose it to a wide format using both old/new and usage of ID and IDLABEL statements.

If you post data as a data step someone can help with the code.

 

Transposing data tutorials:
Long to Wide:
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/

https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/

Wide to Long:
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/

https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/

And sometimes a double transpose is needed for extra wide data sets: <- this is what you need.
https://gist.github.com/statgeek/2321b6f62ab78d5bf2b0a5a8626bd7cd

 


@PauloC wrote:

Hello Experts,

I am a beginner of SAS and need your kind help to find the best way to transpose one table . Any advice will be greatly appreciated.

I have a sample data set as attachment where you can see what i want to do: Thank you very much for your time and help.

ExEx


 

Tom
Super User Tom
Super User

You can probably get there by using two PROC TRANSPOSE steps. First to convert your current wide struction into a tall structure.  Then a second one to convert it back into the even wider version you want.

proc transpose data=have out=tall;
  by p;
run;

proc transpose data=tall out=wide(drop=_name_) delim=_;
  id _name_ p ;
  var col1;
run;

But why do you think that is going to help you?

For most purposes the TALL structure is probably better. Or even your original semi-wide structure.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 426 views
  • 4 likes
  • 3 in conversation