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.
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.
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.
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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.