BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Rhodochrosite | Level 12

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;
1 ACCEPTED SOLUTION

Accepted Solutions
hhchenfx
Rhodochrosite | Level 12

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;

View solution in original post

1 REPLY 1
hhchenfx
Rhodochrosite | Level 12

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1202 views
  • 1 like
  • 1 in conversation