DATA Step, Macro, Functions and more

Non continous do loop

Accepted Solution Solved
Reply
Super Contributor
Posts: 647
Accepted Solution

Non continous do loop

I want to skip iteration 19.

The following doesnt seem to work.

%macro zz;

     data sasdata.som_all;

      set %do i = 10 %to 18, 20 %to 23;
           sasdata.som&i.
           %end;;
     run;
     %mend  zz;
     %zz;


Accepted Solutions
Solution
‎09-11-2013 03:57 PM
Occasional Contributor
Posts: 16

Re: Non continous do loop

How about

%macro zz;

     data sasdata.som_all;

      set %do i = 10 %to 23;

               %IF &i NE 19 %Then sasdata.som&i.;
           %end;;
     run;
%mend  zz;

View solution in original post


All Replies
Solution
‎09-11-2013 03:57 PM
Occasional Contributor
Posts: 16

Re: Non continous do loop

How about

%macro zz;

     data sasdata.som_all;

      set %do i = 10 %to 23;

               %IF &i NE 19 %Then sasdata.som&i.;
           %end;;
     run;
%mend  zz;

Valued Guide
Posts: 2,175

Re: Non continous do loop

have a look at http://communities.sas.com/ideas/1084 a ballot item which seems most relevant to your question. See the comment on 18-May-2013.

Respected Advisor
Posts: 3,777

Re: Non continous do loop

Of course this is the same as program but I bit more general "to me".  For lists of data set you don't even need the macro you could write set som10-som18 some20-some24;  And as mentioned there is the effort to get the syntax of the more robust DO applied to the %DO.  I think we've been waiting on that since 1982.

data som10 som12 som14;
   x=1;
  
run;
%macro zz;
  
%local i skip;
   %let skip = 13,11;
   data som_all;
      set
     
%do i = 10 %to 14;
        
%if %sysfunc(whichn(&i,&skip)) %then %goto continue;
         som&i.
       %
continue: %end;
       ;
     run;
  
%mend  zz;
options mprint=1;
%
zz;

Valued Guide
Posts: 2,175

Re: Non continous do loop

we've been waiting on that since 1982.


we have enough in the macro language
"gild the lily" comes to mind (a half-remembered version of Shakespeare :)
☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 238 views
  • 0 likes
  • 4 in conversation