Hi there,
I need to transpose this data without proc transpose. Here's the data I have:
FALL_SEMESTER_RAW | FALL_SEMESTER_ADJ | SPRING_SEMESTER_RAW | SPRING_SEMESTER_ADJ | |
1 | 89 | 92.2 | 93 | 95.6 |
2 | 83 | 85.6 | 85 | 87.8 |
3 | 96 | 98.9 | 90 | 93.3 |
4 | 93 | 95.6 | 96 | 97.8 |
5 | 66 | 68.9 | 67 | 71.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.
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;
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;
Why can't you use PROC TRANSPOSE?
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.