<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SAS macro to in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to/m-p/958094#M373964</link>
    <description>&lt;P&gt;You left out too many details to tell what you did wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For just TWO cases I wouldn't bother with the %DO loop.&amp;nbsp; Just copy the %INCLUDE statements twice.&lt;/P&gt;
&lt;P&gt;Make sure that all of the code know to use the macro variable to reference the dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsname=riska;
%include ('one.sas' 'two.sas' 'three.sas');
%let dsname=riskb;
%include ('one.sas' 'two.sas' 'three.sas');
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or instead have the code always reference the same WORK dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data for_analysis;
  set riska;
run;
%include ('one.sas' 'two.sas' 'three.sas');
data for_analysis;
  set riskb;
run;
%include ('one.sas' 'two.sas' 'three.sas');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you do need a %DO loop then first make sure it is inside a macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro looper(dslist);
%local i dsname;
%do i=1 %to %sysfunc(countw(&amp;amp;dslist,%str( )));
  %let dsname=%scan(&amp;amp;dslist,&amp;amp;i,%str( ));
%include ......
%end;
%mend looper;
%looper(riska riskb)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps just use a data step to write the code to a file and then include that file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  length dsname $41 ;
  file code;
  do dsname='riska','riskb';
    put '%let ' dsname= ';'
      / '%include "one.sas";'
      / '%include "two.sas";'
    ;
  end;
run;
%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 03 Feb 2025 19:58:24 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-02-03T19:58:24Z</dc:date>
    <item>
      <title>SAS macro to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to/m-p/958093#M373963</link>
      <description>&lt;P&gt;Hi guys, I need some urgent help please. I have two different dataset, and I want to run a bunch of programs based on those datasets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So let's say I have variable dtype -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let dtype = riska riskb; /* these are two different dataset with exact same layout, columns, but slightly different values*/&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 5 programs that I want to run, but I want to run all the programs for a first, then b. so I want to loop through the variable dtype, and do something like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%do 1 %to %sysfunc(countw(%dtype.));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%inc "first_program.sas";&lt;/P&gt;&lt;P&gt;%inc "second_program.sas";&lt;/P&gt;&lt;P&gt;%inc "third_program.sas";&lt;/P&gt;&lt;P&gt;%inc "fourth_program.sas";&lt;/P&gt;&lt;P&gt;%inc "fifth_program.sas";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did something similar, but it's only running riska, but not running riskb. I appreciate any help.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Feb 2025 19:47:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to/m-p/958093#M373963</guid>
      <dc:creator>rodelabrishti</dc:creator>
      <dc:date>2025-02-03T19:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to/m-p/958094#M373964</link>
      <description>&lt;P&gt;You left out too many details to tell what you did wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For just TWO cases I wouldn't bother with the %DO loop.&amp;nbsp; Just copy the %INCLUDE statements twice.&lt;/P&gt;
&lt;P&gt;Make sure that all of the code know to use the macro variable to reference the dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsname=riska;
%include ('one.sas' 'two.sas' 'three.sas');
%let dsname=riskb;
%include ('one.sas' 'two.sas' 'three.sas');
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or instead have the code always reference the same WORK dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data for_analysis;
  set riska;
run;
%include ('one.sas' 'two.sas' 'three.sas');
data for_analysis;
  set riskb;
run;
%include ('one.sas' 'two.sas' 'three.sas');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you do need a %DO loop then first make sure it is inside a macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro looper(dslist);
%local i dsname;
%do i=1 %to %sysfunc(countw(&amp;amp;dslist,%str( )));
  %let dsname=%scan(&amp;amp;dslist,&amp;amp;i,%str( ));
%include ......
%end;
%mend looper;
%looper(riska riskb)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps just use a data step to write the code to a file and then include that file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  length dsname $41 ;
  file code;
  do dsname='riska','riskb';
    put '%let ' dsname= ';'
      / '%include "one.sas";'
      / '%include "two.sas";'
    ;
  end;
run;
%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Feb 2025 19:58:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to/m-p/958094#M373964</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-03T19:58:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to/m-p/958123#M373975</link>
      <description>Thank you Tom, I'm going with the first solution for now.&lt;BR /&gt;%let dsname=riska;&lt;BR /&gt;%include ('one.sas' 'two.sas' 'three.sas');&lt;BR /&gt;%let dsname=riskb;&lt;BR /&gt;%include ('one.sas' 'two.sas' 'three.sas');&lt;BR /&gt;But I want to explore the other one too. I'll post here if I have any questions. I really appreciate it.</description>
      <pubDate>Mon, 03 Feb 2025 21:26:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to/m-p/958123#M373975</guid>
      <dc:creator>rodelabrishti</dc:creator>
      <dc:date>2025-02-03T21:26:19Z</dc:date>
    </item>
  </channel>
</rss>

