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.

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
  • 2 replies
  • 875 views
  • 1 like
  • 2 in conversation