BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Scorpx
Obsidian | Level 7

Hello community,

 

I am trying to make a %do %while nested loop here, can you please check if there is an error? because when I run the code it iterates for  CHAN A and the 12 month but it closes and didn't  do chan B....

 

Thank you

 

%let CHAN=A B C D E;
%let MONTH=JAN FEB MAR APR MAY JUN JUL AGO SEP OCT NOV DEC;

%macro TEST ();

%local i j month_1 chan_1;
%let j=1;
%let i=1;

%do %while (%scan(&chan, &j.) ne );
%let chan_1 = %scan(&chan, &j.);

%do %while (%scan(&month, &i.) ne );
%let month_1 = %scan(&month, &i.);

 /*SOME STEPS HERE*/

   %let i = %eval(&i. + 1);
  
%end;
%let j = %eval(&j. + 1);
%end;

%mend TEST;

Using  SAS EG 7.13

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You forgot to reset I.

Move the %LET I=1 inside the outer loop.

 

Why are you incrementing the loop counter yourself? Why not just let SAS do that?

%do j=1 %to %sysfunc(countw(&chan));
  %let chan_1 = %scan(&chan, &j.);
  %do i=1 %to %sysfunc(countw(&month));

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

You forgot to reset I.

Move the %LET I=1 inside the outer loop.

 

Why are you incrementing the loop counter yourself? Why not just let SAS do that?

%do j=1 %to %sysfunc(countw(&chan));
  %let chan_1 = %scan(&chan, &j.);
  %do i=1 %to %sysfunc(countw(&month));

 

Scorpx
Obsidian | Level 7

Thank you Tom,

 

I did work with your suggestion!

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 673 views
  • 5 likes
  • 2 in conversation