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

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
Barite | Level 11

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
Barite | Level 11

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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