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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.