BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
AmirSari
Quartz | Level 8

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

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.

AmirSari
Quartz | Level 8
Thank you for the code! The dataset is huge and takes forever to run this code. so I split it into 100 smaller datasets.

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
  • 2 replies
  • 1989 views
  • 2 likes
  • 2 in conversation