Calcite | Level 5

## 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

6 REPLIES 6
Tourmaline | Level 20

## Re: Highest and lowest values in observations

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

Data never sleeps
Calcite | Level 5

## 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.....

Diamond | Level 26

## 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.

Rhodochrosite | Level 12

## 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;

Barite | Level 11

## 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_ elim:) min(weight height)=elim1 height

max(weight height)=weight elim2;

run;

## 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_ elim:) min(weight height)=elim1 height
max(weight height)=weight elim2;
run;

proc means data=sashelp.class nway noprint;

class sex;
output out=minmix2(drop=_:) min(height)= max(weight)=;
run;

proc compare base=minmix compare=minmix2 note;

run;
Discussion stats
• 6 replies
• 2229 views
• 0 likes
• 7 in conversation