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;

sas-innovate-2024.png

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.

 

Register now!

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
  • 1373 views
  • 0 likes
  • 2 in conversation