```Date: Fri, 11 Jan 2002 07:08:31 -0500 Reply-To: Gerhard Hellriegel Sender: "SAS(r) Discussion" From: Gerhard Hellriegel Subject: Re: max(x) On Fri, 11 Jan 2002 01:55:34 -0800, xhu wrote: >try > >proc sort data=your_dataset out=new_dataset; >by x; >run; >data dataset1; >set new_dataset end=last; >if last then z=x; >run; > >On Fri, 11 Jan 2002, Sebastian Hein wrote: > >> First I'd like to thank to you good people, who made all helpful >> contributions to my beginners questions on RETAIN or better: lag/ diff/ >> merge-firstobs solution posted yesterday. >> Sorry to bother you with another - probably - simple question: >> How can I get the maximum value from a list (column not row) of values >> and store it in a new variable "Z" ? max(X) does not work, because there >> is only one value inside (see handbook). >> X Z >> . 2 >> 2 2 >> 5 2 >> 7 2 >> 3 2 >> . 2 >> >> >> >> another idea (don't know why it is 2 in the above example, shouldn't it be 7 ??): proc sort data=your_dataset out=new_dataset; by descending x; run; data your_dataset; retain max; set new_dataset; if _n_=1 then max=x; z=max; run; or simpler (you don't need max): proc sort data=your_dataset out=new_dataset; by descending x; run; data your_dataset; retain z; set new_dataset; if _n_=1 then z=x; run; another possibility (if you need the maximum at other places too: proc sort data=your_dataset out=new_dataset; by descending x; run; data _null_; set new_dataset; if _n_=1 then call symput("max",x); stop; run; data your_dataset; set new_dataset; z=&max; run; ```

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