BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10

 

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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.

PeterClemmensen
Tourmaline | Level 20

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;
BrahmanandaRao
Lapis Lazuli | Level 10

Thank you 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 3 replies
  • 604 views
  • 1 like
  • 3 in conversation