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
SQL using min() and max() aggregate functions...
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.....
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.
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;
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;
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?
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.