Programming the statistical procedures from SAS

Transpose Data

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Transpose Data

Hi there,

I need to transpose this data without proc transpose. Here's the data I have:

FALL_SEMESTER_RAWFALL_SEMESTER_ADJSPRING_SEMESTER_RAWSPRING_SEMESTER_ADJ
18992.29395.6
28385.68587.8
39698.99093.3
49395.69697.8
56668.96771.1

And I would like the data to look like this:

ID      SEMESTER      TYPE      SCORE

1     FALL                    ADJ          XX

1     FALL                    RAW         XX

1     SPRING               ADJ          XX

1      SPRING          RAW            XX

...

This is what I tried but not working out too well. Any help is appreciated.


Accepted Solutions
Solution
‎08-17-2015 08:21 AM
Super User
Posts: 9,769

Re: Transpose Data

Code: Program

data have;
infile cards truncover expandtabs;
input FALL_SEMESTER_RAW FALL_SEMESTER_ADJ SPRING_SEMESTER_RAW SPRING_SEMESTER_ADJ;
cards;
89 92.2 93 95.6
83 85.6 85 87.8
96 98.9 90 93.3
93 95.6 96 97.8
66 68.9 67 71.1
;
run;
data want;
set have;
array x{*} _numeric_;
ID=_n_;  
do i=1 to dim(x);
  SEMESTER=scan(vname(x{i}),1,'_');
  TYPE=scan(vname(x{i}),-1,'_');
  SCORE=x{i};
  output;
end;
keep ID   SEMESTER   TYPE   SCORE ;
run;

View solution in original post


All Replies
Solution
‎08-17-2015 08:21 AM
Super User
Posts: 9,769

Re: Transpose Data

Code: Program

data have;
infile cards truncover expandtabs;
input FALL_SEMESTER_RAW FALL_SEMESTER_ADJ SPRING_SEMESTER_RAW SPRING_SEMESTER_ADJ;
cards;
89 92.2 93 95.6
83 85.6 85 87.8
96 98.9 90 93.3
93 95.6 96 97.8
66 68.9 67 71.1
;
run;
data want;
set have;
array x{*} _numeric_;
ID=_n_;  
do i=1 to dim(x);
  SEMESTER=scan(vname(x{i}),1,'_');
  TYPE=scan(vname(x{i}),-1,'_');
  SCORE=x{i};
  output;
end;
keep ID   SEMESTER   TYPE   SCORE ;
run;
SAS Super FREQ
Posts: 3,547

Re: Transpose Data

Why can't you use PROC TRANSPOSE?

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 253 views
  • 0 likes
  • 3 in conversation