BookmarkSubscribeRSS Feed
KrishnaChandra
Calcite | Level 5

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 

6 REPLIES 6
LinusH
Tourmaline | Level 20

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

Data never sleeps
vasu
Calcite | Level 5

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

KachiM
Rhodochrosite | Level 12

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;

Loko
Barite | Level 11

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;

data_null__
Jade | Level 19

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1995 views
  • 0 likes
  • 7 in conversation