06-11-2013 07:55 AM
I need some help collapsing data into a single row. I've created a data set that creates a flag for the test each student has taken (see table). The problem is I need this data to be one row per student and can't figure out how to code this properly. I've provided an example below.
|Student||Test||Flag A||Flag B||Flag C|
Desired Output Data:
|Student||Flag A||Flag B||Flag C|
Is there a sas procedure I could use in this situation? Any help would be much appreciated.
06-11-2013 09:30 AM
Try with the following code...Although it is hard coded at one place to recreate the flags,it meets your requirement...
input student $ test $ flag1 - flag3;
Carl A 1 0 0
Carl B 0 1 0
Tito A 1 0 0
Tito B 0 1 0
Tito C 0 0 1
proc sql noprint;
create table have1 as
select student,count(student) as no_of_student
group by 1;
select max(no_of_student) into :max
data want(drop = i);
do i = 1 to &max.;
flag(i) = 1;
if no_of_student < &max. then do;
flag3 = 0;
/*Based on your requirement, add more flags*/
Need further help from the community? Please ask a new question.