Hi,
I have 2 datasets, 1 data with date and value, and the other data has start and end date.
I want to find the Max value between start and end date.
I can do it with my code below but I think there should be a better way using Proc SQL.
Can you please help?
Thanks,
HHC
data have;
input date value;
datalines;
1 5
2 6
3 8
4 1
5 9999
6 99
;run;
data condition;
input start end;
datalines;
2 4
3 6
;run;
proc sql;
create table temp as select * from condition as a left join have as b
on a.start<=b.date<a.end; quit;
proc sort data=temp; by start end descending value;
data want; set temp;
by start end;
if first.end; run;
That one is better, short and clear
data w; set condition;
max=0;
do i=start to end-1;
set have point=i;
if start<=date<end then do;
if max<value then max=value;
end;
end;
run;
That one is better, short and clear
data w; set condition;
max=0;
do i=start to end-1;
set have point=i;
if start<=date<end then do;
if max<value then max=value;
end;
end;
run;
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.
Ready to level-up your skills? Choose your own adventure.