Hi there,
I have the following data set (screenshot). What I want to do is to collapse the IDs, Semesters, Adjusted, Raw, and Scores.
Want:
ID Semester Type Score
1 Fall Raw xx
1 Fall Adj xx
1 Spring Raw xx
1 Spring Adj xx
...
I have started something like this...but it doesn't seem to be working out well. And I know the retain has to be there somewhere as well..
data want;
set have;
by id ;
if FIRST.ID THEN DO;
IF FALL_SEMESTER_RAW>0 THEN SEMESTER= 'FALL';
IF SPRING_SEMESTER_RAW>0 THEN SEMESTER= 'SPRING';
ELSE;
*if SPRING_SEMESTER_RAW>0 THEN SEMESTER=SPRING_SEMESTER_ADJ;
END;
RUN;
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 |
Sorry, could you clarify hy you do not want to use Transpose? Seeing as that procedure is specifically built to transpose data as fast and consisely as possible it makes no sense to not use it:
data have;
input id semester $ type $ score;
id_var=catx("_",upcase(semester),"SEMESTER",upcase(type));
datalines;
1 Fall Raw 89
1 Fall Adj 92.2
1 Spring Raw 93
1 Spring Adj 95.6
2 Fall Raw 83
2 Fall Adj 85.6
2 Spring Raw 85
2 Spring Adj 87.8
;
run;
proc sort data=have;
by id id_var;
run;
proc transpose data=have out=want;
by id;
var score;
id id_var;
idlabel id_var;
run;
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 25. Read more here about why you should contribute and what is in it for you!
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.