Date: Wed, 12 Mar 2003 00:30:38 GMT
Reply-To: julierog@ix.netcom.com
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Roger Lustig <trovato@BELLATLANTIC.NET>
Subject: Re: grouping and creating datasets
Content-Type: text/plain; charset=us-ascii; format=flowed
Dear Leyla:
You seem to be almost there. Try this:
data
increase
decrease
flat
mixed
;
set grades;
by student;
retain oldgrade;
if first.student then do;
increase=0; decrease=0;
end;
else do;
*** German-style grades: 1 is best;
*** Don't try this in Switzerland!;
if grade < oldgrade then increase + 1;
else if grade > oldgrade then decrease + 1;
***Assumes that every student has 2 or more grades;
***Also assumes that you want only one record per student;
if last.student then do;
if increase and decrease then output mixed;
else if decrease then output decrease;
else if increase then output increase;
else output flat;
end;
end;
oldgrade=grade;
keep student;
run;
This can be done more elegantly with a DOW-loop, of course.
Best,
Roger Lustig
leyla yerlikaya wrote:
> Hello all,
>
> I would like to create four different datasets. One of the datasets
> includes all of the students whose grades only improved over the time
> (dataset 1). The other one will include all of the students whose grades
> decreased (dataset 2), another one will include all the students whose
> records stayed the same (dataset 3), and the last one will include the
> students whose grades both increased and decreased.
>
> For instance, if I use the following sample dataset student A should be
> in the dataset1, student B should be in the dataset 3, student C should
> be in the dataset 2, and the student D should be in the dataset 4.
>
> Student Grade
>
> A 5
>
> A 3
>
> A 3
>
> B 4
>
> B 4
>
> B 4
>
> B 4
>
> C 3
>
> C 5
>
> C 5
>
> D 5
>
> D 4
>
> D 5
>
> D 4
>
> D 5
>
> I wrote a code that calculates the 'difference' of the first and second,
> second and the third, ... grades for each student. I also generated
> dummy variables using this 'difference' variable which help to
> understand if that grade increased or decreased.
>
> Now my dataset looks like this:
>
>
>
> Student Grade difference increase decrease nochange
>
> A 5 -2 0
> 1 0
>
> A 3 0 0
> 0 1
>
> A 3 .
>
> B 4 0 0
> 0 1
>
> B 4 0 0
> 0 1
>
> B 4 0
> 0 0 1
>
> B 4 .
>
> C 3 +2 1
> 0 0
>
> C 5 0 0
> 0 0
>
> C 5 .
>
> D 5 -1 0
> 1 0
>
> D 4
> +1 1 0 0
>
> D
> 5 -1 0 1 0
>
> D 4
> +1 1 0 0
>
> D 5 .
>
>
>
> I will appreciate if you could give me a couple of hints on creating my
> datasets after this point.
>
>
>
> Thanks,
>
> leyla
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> ------------------------------------------------------------------------
> Add photos to your messages with MSN 8. <http://g.msn.com/8HMFENUS/2749>
> Get 2 months FREE*.
|