Highest and lowest values in observations

Reply
Frequent Contributor
Posts: 89

Highest and lowest values in observations

Hai all,

    I would like to know how to  find the minimum value of stdate by id also highest value of enddate by id

   id                                               stdate                                           enddate

please help me 

Super User
Posts: 5,375

Re: Highest and lowest values in observations

SQL using min() and max() aggregate functions...

Data never sleeps
New Contributor
Posts: 2

Re: Highest and lowest values in observations

Try this.

data dates;

     set olddates;

     if not missing (stdate) then stdate_n=input(stdate,B8601DT19.);

     if not missing (enddate) then enddate_n=input(enddate,B8601DT19.);

run;

***********For min stdate;

proc sort data=stdate_min;

     by id stdate_n;

run;

data stdate_min;

     set stdate_min;

     by id stdate_n;

     if first.id;

run;

**********In the same way we can find out max value of endate;

proc sort data=enddate_min;

     by id enddate_n;

run;

data enddate_min;

     set enddate_min;

     by id enddate_n;

     if last.id;

run;

Please check not tried on the data.....

Super User
Super User
Posts: 7,668

Re: Highest and lowest values in observations

You can combine them, sort and if last or first then output.  Min/max also good in SQL.  You could also proc means/summary your data.

Super Contributor
Posts: 290

Re: Highest and lowest values in observations

Do you want a data step programming?

It is just a simple program !

data have;           

input id stdate  enddate;

datalines;

10  1    5

10  3    7

10  2    .

15  7   10

15  8    .

20  3   15

20  5   .

20  7   20

;

run;

data want;

   do until(last.id);

      set have;

      by id;

      if first.id then do; mindate = 9999999; maxdate = -9999999; end;

      if stdate < mindate then mindate = stdate;

      if enddate > 0 and enddate > maxdate then maxdate = enddate;

   end;

drop stdate enddate;

run;

Super Contributor
Posts: 308

Re: Highest and lowest values in observations

Hello,

Based on Sashelp.class:

proc means data=sashelp.class nway noprint;

class sex;

var weight height;

output out=minmix(drop=_type_ _freq_ elimSmiley Happy min(weight height)=elim1 height

max(weight height)=weight elim2;

run;

Respected Advisor
Posts: 3,782

Re: Highest and lowest values in observations

Loko wrote:

Hello,

Based on Sashelp.class:

proc means data=sashelp.class nway noprint;

class sex;

var weight height;

output out=minmix(drop=_type_ _freq_ elim:) min(weight height)=elim1 height

max(weight height)=weight elim2;

run;

You don't need ELIM.  You don't think SAS would make a syntax that was that clunky do you?

proc means data=sashelp.class nway noprint;
class sex;
var weight height;
output out=minmix(drop=_type_ _freq_ elimSmiley Happy min(weight height)=elim1 height
max(weight height)=weight elim2;
run;

proc means data=sashelp.class nway noprint;
  
class sex;
   output out=minmix2(drop=_Smiley Happy min(height)= max(weight)=;
   run;

proc compare base=minmix compare=minmix2 note;
  
run;
Ask a Question
Discussion stats
  • 6 replies
  • 306 views
  • 0 likes
  • 7 in conversation