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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1242 views
  • 1 like
  • 1 in conversation