Date: Fri, 23 Oct 2009 00:36:39 -0700
Reply-To: shiva <shiva.saidala@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: shiva <shiva.saidala@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: How to make the dummy variable based on 3 criteria? Please
help.
Content-Type: text/plain; charset=ISO-8859-1
Hi lipty,
I dont know is it an optimal solution.but try it out.
Hope this helps
data test;
input year hospital branch $ N ;
cards;
1989 1 b1 22
1989 1 b2 23
1989 1 b3 22
1989 1 b4 24
1989 1 b5 24
1990 6 b1 55
1990 6 b2 33
1990 6 b4 77
1990 6 b5 33
1990 10 b2 66
1990 10 b3 66
1990 10 b4 66
1990 11 b2 67
1990 11 b3 67
1990 11 b4 67
;
run;
proc sort data=test out=test1;by year hospital n;run;
data final(keep = year hospital new);
set test1;
by year hospital n;
n1=lag(n);
if first.hospital then n1=.;
if lag(n1)=n then new=0;
else if last.hospital then new=1;
if last.hospital;
run;
Thanks,
shiva
|