DATA Step, Macro, Functions and more

Do loop

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

Do loop

Hi,

 

I'm trying to do a do loop with proc sql. The following part of the script gives an error message:

 

%let totalobs = 100;

%let totalobs = &totalobs. + 1;

%put totalobs;

 

ERROR: Open code statement recursion detected.

 

Does anyone know what the issue is?

Thank you!


Accepted Solutions
Solution
Thursday
PROC Star
Posts: 1,798

Re: Do loop

Your code works fine

 

%let totalobs = 100;

%let totalobs = &totalobs. + 1;

%put totalobs=&totalobs;


/*or*/

%let totalobs = 100;

%let totalobs = %eval(&totalobs. + 1);

%put totalobs=&totalobs;

View solution in original post


All Replies
Solution
Thursday
PROC Star
Posts: 1,798

Re: Do loop

Your code works fine

 

%let totalobs = 100;

%let totalobs = &totalobs. + 1;

%put totalobs=&totalobs;


/*or*/

%let totalobs = 100;

%let totalobs = %eval(&totalobs. + 1);

%put totalobs=&totalobs;

Contributor
Posts: 23

Re: Do loop

Posted in reply to novinosrin

I still get the same error

PROC Star
Posts: 1,798

Re: Do loop

Try to restart SAS and rerun

 

Here is my log:

 

1840 %let totalobs = 100;
1841
1842 %let totalobs = &totalobs. + 1;
1843
1844 %put totalobs=&totalobs;
totalobs=100 + 1
1845
1846
1847 /*or*/
1848
1849 %let totalobs = 100;
1850
1851 %let totalobs = %eval(&totalobs. + 1);
1852
1853 %put totalobs=&totalobs;
totalobs=101

 

Contributor
Posts: 23

Re: Do loop

Posted in reply to novinosrin

It works. Thank you so much

Super User
Posts: 6,765

Re: Do loop

You might get that message if you made the mistake of omitting the first semicolon at the end of the first %LET statement.  If that's not the cause, we might need to see the log including the SQL piece.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 71 views
  • 0 likes
  • 3 in conversation