PROC TRANSPOSE can transpose both numeric and character data, but the result is not easy to read. By default, the procedure will transpose all numerics without using a VAR statement. In order to transpose both numeric and character, you must list all variables to be transposed on the VAR statement.
Mixed data values of character and numeric that will occupy the same column must be of the same data type in accordance with SAS data rules. All numeric values are converted to character. However, the end result is not easy to look at because the alignment of the data continues to follow the typical alignment in place prior to the transpose. The new character numbers are right justified and the original character text values are left justified. This can make it difficult to read down the columns when examining the output.
The sample in the Full Code tab shows how to use an ARRAY and the RIGHT function to right justify the data. You can also use either the LEFT or STRIP function to left justify the data.
In the Results/Output tab you can see the unjustified and the justified output.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
proc sort data=sashelp.class;
by sex;
run;
proc transpose data=sashelp.class out=stuff(rename=(_name_= Category)) prefix=Data;
by sex;
var name age height weight;
run;
proc print data=stuff;
title 'Stuff dataset not justified';
run;
data stuff;
set stuff;
array justr(*) _character_;
do i=1 to dim(justr);
justr(i)=right(justr(i));
end;
drop i;
run;
proc print;
title 'Stuff dataset right justified';
run;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Stuff dataset not justified Obs Sex Category Data1 Data2 Data3 Data4 Data5 1 F Name Joyce Jane Louise Alice Barbara 2 F Age 11 12 12 13 13 3 F Height 51.3 59.8 56.3 56.5 65.3 4 F Weight 50.5 84.5 77 84 98 5 M Name Thomas James John Robert Jeffrey 6 M Age 11 12 12 12 13 7 M Height 57.5 57.3 59 64.8 62.5 8 M Weight 85 83 99.5 128 84 Obs Data6 Data7 Data8 Data9 Data10 1 Carol Judy Janet Mary 2 14 14 15 15 3 62.8 64.3 62.5 66.5 4 102.5 90 112.5 112 5 Alfred Henry Ronald William Philip 6 14 14 15 15 16 7 69 63.5 67 66.5 72 8 112.5 102.5 133 112 150 Stuff dataset right justified Obs Sex Category Data1 Data2 Data3 Data4 Data5 Data6 Data7 Data8 Data9 Data10 1 F Name Joyce Jane Louise Alice Barbara Carol Judy Janet Mary 2 F Age 11 12 12 13 13 14 14 15 15 3 F Height 51.3 59.8 56.3 56.5 65.3 62.8 64.3 62.5 66.5 4 F Weight 50.5 84.5 77 84 98 102.5 90 112.5 112 5 M Name Thomas James John Robert Jeffrey Alfred Henry Ronald William Philip 6 M Age 11 12 12 12 13 14 14 15 15 16 7 M Height 57.5 57.3 59 64.8 62.5 69 63.5 67 66.5 72 8 M Weight 85 83 99.5 128 84 112.5 102.5 133 112 150
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> TRANSPOSE |
Date Modified: | 2020-12-16 11:48:51 |
Date Created: | 2011-05-06 15:15:51 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | Microsoft® Windows® for 64-Bit Itanium-based Systems | ||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
z/OS | ||||
Z64 | ||||
OpenVMS VAX | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2003 for x64 | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2008 for x64 | ||||
Microsoft Windows XP Professional | ||||
Windows 7 Enterprise 32 bit | ||||
Windows 7 Enterprise x64 | ||||
Windows 7 Home Premium 32 bit | ||||
Windows 7 Home Premium x64 | ||||
Windows 7 Professional 32 bit | ||||
Windows 7 Professional x64 | ||||
Windows 7 Ultimate 32 bit | ||||
Windows 7 Ultimate x64 | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
Windows Vista for x64 | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX |