title: SAS Macro to loop through datasets
body: <p>I have a bunch of datasets named after dates (for example, 20130102) in a library called taq. Normally when I tried to read in multiple datasets I would do <code>set taq.cq_&amp;yyyymmdd:;</code>. So that if I input yyyymmdd as 201201, it will fetch all the datasets starting with the prefix 201201. </p>
  
  <p>However, now I am trying to run a macro looping across all datasets. Ideally: </p>
  
  <pre><code>%MACRO EXAMPLE(DATE_VAR);
      DO WHILE(...);
        %ANOTHER_MACRO(SOMETHING);
      END;
  %MEND;
  </code></pre>
  
  <p>If I input <code>%EXAMPLE(201301);</code> , it will call another macro which executes on every dataset starting with the prefix 201301. </p>
  
  <p>I was wondering how to design a do loop to do that? </p>
  
  <p>I have read some posts on <a href="https://communities.sas.com/t5/General-SAS-Programming/execute-same-procedure-over-multiple-datasets/td-p/166407" rel="nofollow noreferrer">SAS forum</a> and <a href="https://stackoverflow.com/questions/30643590/sas-macro-for-multiple-datasets">StackOverflow</a>. But it seems that they either run the macro on all of the datasets, or they require a manual input of a list of datasets that I am running on. I am trying to make the procedure automatic (that is, the program can detect all the datasets with a prefix itself.)</p>