BookmarkSubscribeRSS Feed
Ivy
Quartz | Level 8 Ivy
Quartz | Level 8

 

Hello, 

 

I am trying to run a loop in a Macro program. 

 

I would like to go back to the loop if there is no observation in test2 .  Is there any way for that ?  Thank you very much. 

 

%macro test ;

 

data test1;

set  test;

where  ;

run;

 

%do i= 1 %to 41;

data test2;

set test1;

where .....;

run;

 

..........

 

 

%end;

 

%mend; 

1 REPLY 1
ChrisNZ
Tourmaline | Level 20

Here is one way. Does it suit you?

%do i= 1 %to 41;

 proc sql;
   create table test2 as
   select *
   from test1
   where .....;
 run; 
 %if  &sqlobs=0 %then %goto next_iteration;
  
 ..........
 
 %next_iteration: 
%end;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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
  • 1 reply
  • 675 views
  • 1 like
  • 2 in conversation