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.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: