Hi everyone,
I am trying to run a proc sql for 100 datasets and was wondering if it is possible to use a do loop instead of writing the same code 100 times. here is my proc sql:
proc sql; create table new&i as select distinct a.*,b.date, b.date2, b.x, b.y, b.z from v&i a, &data b where abs(intck('day',a.date,b.date))<=29 group by a.id, a.date having abs(a.date2-b.date2) eq min(abs(a.date2-b.date2)) ; quit;
Any help is greatly appreciated!
Use a macro loop:
%macro loop;
%do i = 1 %to 100;
create table new&i as
select distinct a.*,b.date, b.date2, b.x, b.y, b.z
from v&i a, &data b
where abs(a.date-b.date)<=29
group by a.id, a.date
having abs(a.date2-b.date2) eq min(abs(a.date2-b.date2))
;
%end;
%mend;
proc sql;
%loop
quit;
What keeps you from combining the 100 datasets into one in the first place?
Since dates are counts of days, you don't need the INTCK function. A simple subtraction will be faster.
Use a macro loop:
%macro loop;
%do i = 1 %to 100;
create table new&i as
select distinct a.*,b.date, b.date2, b.x, b.y, b.z
from v&i a, &data b
where abs(a.date-b.date)<=29
group by a.id, a.date
having abs(a.date2-b.date2) eq min(abs(a.date2-b.date2))
;
%end;
%mend;
proc sql;
%loop
quit;
What keeps you from combining the 100 datasets into one in the first place?
Since dates are counts of days, you don't need the INTCK function. A simple subtraction will be faster.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.