Hi Guys Good Morning I want output rows as columns and columns as rows from below dataset
but this output only using datastep not with proc transpose
data avg_WH;
input Age $ 1-5 Weight $ 7-25 Height $ 26-42 ;
cards;
13yrs 100.0 lb (45.3 kg) 61.5" (156.2 cm)
14yrs 112.0 lb (50.8 kg) 64.5" (163.8 cm)
15yrs 123.5 lb (56.0 kg) 67.0" (170.1 cm)
16yrs 134.0 lb (60.8 kg) 68.3" (173.4 cm)
17yrs 142.0 lb (64.4 kg) 69.0" (175.2 cm)
18yrs 147.5 lb (66.9 kg) 69.2" (175.7 cm)
19yrs 152.0 lb (68.9 kg) 69.5" (176.5 cm)
20yrs 155.0 lb (70.3 kg) 69.7" (177 cm)
;
run;
Why do you want to do something like this in a data step? You can do something like this
data avg_WH;
input Age $ 1-5 Weight $ 7-25 Height $ 26-42 ;
cards;
13yrs 100.0 lb (45.3 kg) 61.5" (156.2 cm)
14yrs 112.0 lb (50.8 kg) 64.5" (163.8 cm)
15yrs 123.5 lb (56.0 kg) 67.0" (170.1 cm)
16yrs 134.0 lb (60.8 kg) 68.3" (173.4 cm)
17yrs 142.0 lb (64.4 kg) 69.0" (175.2 cm)
18yrs 147.5 lb (66.9 kg) 69.2" (175.7 cm)
19yrs 152.0 lb (68.9 kg) 69.5" (176.5 cm)
20yrs 155.0 lb (70.3 kg) 69.7" (177 cm)
;
run;
data want(keep=var:);
array _{3} $20 Age Weight Height;
array var{8} $20;
do i=1 to 3;
do j=1 to 8;
set avg_WH point=j;
var[j]=_[i];
end;
output;
end;
stop;
run;
Please post working data step code for example data. Your code gives me this log:
27 data avg_W&H;
_
22
200
ERROR 22-322: Syntaxfehler, erwartet wird eines der folgenden: ein Name, eine Zeichenkette in Hochkommata, (, /, ;, _DATA_, _LAST_,
_NULL_.
ERROR 200-322: The symbol is not recognized and will be ignored.
28 input Age Weight Height ;
29 cards;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.AVG_W may be incomplete. When this step was stopped there were 0 observations and 3 variables.
WARNING: The data set WORK.H may be incomplete. When this step was stopped there were 0 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
As the name says, the proper tool for TRANSPOSING is proc TRANSPOSE.
Why do you want to do something like this in a data step? You can do something like this
data avg_WH;
input Age $ 1-5 Weight $ 7-25 Height $ 26-42 ;
cards;
13yrs 100.0 lb (45.3 kg) 61.5" (156.2 cm)
14yrs 112.0 lb (50.8 kg) 64.5" (163.8 cm)
15yrs 123.5 lb (56.0 kg) 67.0" (170.1 cm)
16yrs 134.0 lb (60.8 kg) 68.3" (173.4 cm)
17yrs 142.0 lb (64.4 kg) 69.0" (175.2 cm)
18yrs 147.5 lb (66.9 kg) 69.2" (175.7 cm)
19yrs 152.0 lb (68.9 kg) 69.5" (176.5 cm)
20yrs 155.0 lb (70.3 kg) 69.7" (177 cm)
;
run;
data want(keep=var:);
array _{3} $20 Age Weight Height;
array var{8} $20;
do i=1 to 3;
do j=1 to 8;
set avg_WH point=j;
var[j]=_[i];
end;
output;
end;
stop;
run;
Thank you
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.