BookmarkSubscribeRSS Feed
ali_hash
Calcite | Level 5

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_RAWFALL_SEMESTER_ADJSPRING_SEMESTER_RAWSPRING_SEMESTER_ADJ
18992.29395.6
28385.68587.8
39698.99093.3
49395.69697.8
56668.96771.1
1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is ANOVA?

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.

Discussion stats
  • 1 reply
  • 1410 views
  • 0 likes
  • 2 in conversation