```Date: Tue, 7 Dec 2010 22:17:07 +0800 Reply-To: Murphy Choy Sender: "SAS(r) Discussion" From: Murphy Choy Subject: Re: how to solve this senario? Comments: To: Nway In-Reply-To: <201012071400.oB7BloEY025719@willow.cc.uga.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi, Try this. data test; input Patid text \$ text2 \$ vrd val; datalines; 1 b s 0 . 1 b s 1 . 1 b s 2 . 1 b u 0 . 1 b u 1 . 1 b u 2 . 1 x s 0 23 1 x s 1 23 1 x s 2 23 1 x u 0 12 1 x u 1 12 1 x u 2 12 ; run; data test2; set test; output; if text = 'x' then do; text = 'z';val = .;output; end; run; proc sort data = test2; by text text2 vrd; run; proc sort data = test2; by descending val text text2 vrd ; run; data test3; set test2; retain val2; by descending val text text2; if first.text2 then do; if text2 = 's' then val2 = 23; else val2 = 12; end; val = val2; drop val2; run; On 07/12/2010 10:00 PM, Nway wrote: > Hi All, > > I have data like > > Patid text text2 vrd val > 1 b s 0 . > 1 b s 1 . > 1 b s 2 . > 1 b u 0 . > 1 b u 1 . > 1 b u 2 . > 1 x s 0 23 > 1 x s 1 23 > 1 x s 2 23 > 1 x u 0 12 > 1 x u 1 12 > 1 x u 2 12 > > > I need out put like > > Patid text text2 vrd val > 1 b s 0 . > 1 b s 1 . > 1 b s 2 . > 1 b u 0 . > 1 b u 1 . > 1 b u 2 . > 1 x s 0 23 > 1 x s 1 23 > 1 x s 2 23 > 1 x u 0 12 > 1 x u 1 12 > 1 x u 2 12 > 1 z s 0 . > 1 z s 1 . > 1 z s 2 . > 1 z u 0 . > 1 z u 1 . > 1 z u 2 . > > > > HOw to retain a value before and after text2 variable wise? > > I want output like this. > > Patid text text2 vrd val > 1 b s 0 23 > 1 b s 1 23 > 1 b s 2 23 > 1 b u 0 12 > 1 b u 1 12 > 1 b u 2 12 > 1 x s 0 23 > 1 x s 1 23 > 1 x s 2 23 > 1 x u 0 12 > 1 x u 1 12 > 1 x u 2 12 > 1 z s 0 23 > 1 z s 1 23 > 1 z s 2 23 > 1 z u 0 12 > 1 z u 1 12 > 1 z u 2 12 > > > Thanks, > Nway -- Regards, Murphy Choy Certified Advanced Programmer for SAS V9 Certified Basic Programmer for SAS V9 DataShaping Certified SAS Professional ```

Back to: Top of message | Previous page | Main SAS-L page