Programming the statistical procedures from SAS

Transposing Data without Proc Transpose

Reply
Occasional Contributor
Posts: 10

Transposing Data without Proc Transpose

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
Super User
Super User
Posts: 7,565

Re: Transposing Data without Proc Transpose

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;

Ask a Question
Discussion stats
  • 1 reply
  • 225 views
  • 0 likes
  • 2 in conversation