General form, PROC TRANSPOSE:
PROC TRANSPOSE <DATA=input-data-set>
<OUT=output-data-set>
<NAME=prefix
text>
<PREFIX=variable-name>;
BY <DESCENDING> variable-1
<...<DESCENDING> variable-n>
<NOTSORTED>;
VAR variable(s);
RUN;
DATA=input-data-set
names the SAS data
set to transpose.
OUT=output-data-set
names the output data
set.
NAME=variable-name
specifies the name
for the variable in the output data set that contains the name of
the variable that is being transposed to create the current observation.
PREFIX=variable-name
specifies a prefix
to use in constructing names for transposed variables in the output
data set. For example, if PREFIX=VAR, the names of the variables are
VAR1, VAR2, ...,VARn.
BY statement
is used to transpose
each BY group.
VAR variable(s)
names one or more variables
to transpose.
|
proc transpose data=sasuser.ctargets
out=work.ctarget2;
run;
Year
|
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
---|---|---|---|---|---|---|
1997
|
192284420
|
86376721
|
28526103
|
260386468
|
109975326
|
102833104
|
1998
|
108645734
|
147656369
|
202158055
|
41160707
|
264294440
|
267135485
|
1999
|
85730444
|
74168740
|
39955768
|
312654811
|
318149340
|
187270927
|
Obs
|
_NAME_
|
COL1
|
COL2
|
COL3
|
---|---|---|---|---|
1
|
Year
|
1997
|
1998
|
1999
|
2
|
Jan
|
192284420
|
108645734
|
85730444
|
3
|
Feb
|
86376721
|
147656369
|
74168740
|
4
|
Mar
|
28526103
|
202158055
|
39955768
|
5
|
Apr
|
260386468
|
41160707
|
31265481
|
6
|
May
|
109975326
|
264294440
|
318149340
|
7
|
Jun
|
102833104
|
267135485
|
187270927
|
8
|
Jul
|
196728648
|
208694865
|
123394421
|
9
|
Aug
|
236996122
|
83456868
|
34273985
|
10
|
Sep
|
112413744
|
286846554
|
151565752
|
11
|
Oct
|
125401565
|
275721406
|
141528519
|
12
|
Nov
|
72551855
|
230488351
|
178043261
|
13
|
Dec
|
136042505
|
24901752
|
181668256
|
proc transpose data=sasuser.ctargets out=work.ctarget2 name=Month prefix=Ctarget; run;
Obs
|
Month
|
Ctarget1
|
Ctarget2
|
Ctarget3
|
---|---|---|---|---|
1
|
Year
|
1997
|
1998
|
1999
|
2
|
Jan
|
192284420
|
108645734
|
85730444
|
3
|
Feb
|
86376721
|
147656369
|
74168740
|
4
|
Mar
|
28526103
|
202158055
|
39955768
|
5
|
Apr
|
260386468
|
41160707
|
31265481
|
6
|
May
|
109975326
|
264294440
|
318149340
|
7
|
Jun
|
102833104
|
267135485
|
187270927
|
8
|
Jul
|
196728648
|
208694865
|
123394421
|
9
|
Aug
|
236996122
|
83456868
|
34273985
|
10
|
Sep
|
112413744
|
286846554
|
151565752
|
11
|
Oct
|
125401565
|
275721406
|
141528519
|
12
|
Nov
|
72551855
|
230488351
|
178043261
|
13
|
Dec
|
136042505
|
24901752
|
181668256
|
proc transpose data=sasuser.ctargets out=work.ctarget2 (rename=(col1=Ctarget1 col2=Ctarget2 col3=Ctarget3)) name=Month; run;
proc transpose data=sasuser.ctargets out=work.ctarget2 name=Month prefix=Ctarget; run; proc print data=work.ctarget2 label; label Month=MONTH; run;