<?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: Run a macro with a changing input dataset each time without having to specify the input dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Run-a-macro-with-a-changing-input-dataset-each-time-without/m-p/595173#M171174</link>
    <description>&lt;P&gt;Thank you. Worked perfect!&lt;/P&gt;</description>
    <pubDate>Wed, 09 Oct 2019 19:18:25 GMT</pubDate>
    <dc:creator>slottemc</dc:creator>
    <dc:date>2019-10-09T19:18:25Z</dc:date>
    <item>
      <title>Run a macro with a changing input dataset each time without having to specify the input dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-a-macro-with-a-changing-input-dataset-each-time-without/m-p/595150#M171171</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I want to run the below macro using &amp;amp;name as the input dataset, but I have over a hundred datasets I need to run this through. I originally wanted to do the macro as a by group but it does not look like it has that functionality and instead has to be run one at a time. What is the best way to change the input dataset names?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%forecast (data=unixwork.&amp;amp;name, var=rate, id=date, interval=month,
           project=projtest_fcb, entry=forecast, out=unixwork.forecast_fcb, 
           climit=95, horizon=4, keep=1);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The values of &amp;amp;name would be...&lt;/P&gt;&lt;P&gt;1)BCS_CHMO&lt;/P&gt;&lt;P&gt;2)BCS_CPPO&lt;/P&gt;&lt;P&gt;3)BCS_XHMO&lt;/P&gt;&lt;P&gt;4)COL_CHMO&lt;/P&gt;&lt;P&gt;5)COL_CPPO&lt;/P&gt;&lt;P&gt;6)CISDTP_XHMO&lt;/P&gt;&lt;P&gt;7)PPC1_XPPO&lt;/P&gt;&lt;P&gt;etc. like I said over 100 of these values&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had all of these in a KEY column in my original table, but then I split it all out into their own datasets, but now I think I didn't need to do that, but probably could have used some type of call symput or %Syscall set to change the value of &amp;amp;name and run the macro and keep doing until each &amp;amp;name is run?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data input;
input KEY product measure $ date rate;
datalines ;
BCS_CHMO     CHMO BCS    01JAN2016 .5432
BCS_CPPO     CPPO BCS    01JAN2016 .4567
BCS_XHMO     XHMO BCS    01JAN2016 .4321
COL_CHMO     CHMO COL    01JAN2016 .5678
COL_CPPO     CPPO COL    01JAN2016 .4567
CISDTP_XHMO  XHMO CISDTP 01JAN2016 .2345
PPC1_XPPO    XPPO PPC1   01JAN2016 .3210
;
data _null_;
 if _n_=1 then do;
   if 0 then set input;
   declare hash h(dataset:'input(obs=0)',multidata:'y');
   h.definekey(all:'y');
   h.definedata(all:'y');
   h.definedone();
 end;
do until(last.key);
 set input;
 by key;
 h.add();
end;
h.output(dataset:key);
h.clear();
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2019 17:55:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-a-macro-with-a-changing-input-dataset-each-time-without/m-p/595150#M171171</guid>
      <dc:creator>slottemc</dc:creator>
      <dc:date>2019-10-09T17:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Run a macro with a changing input dataset each time without having to specify the input dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-a-macro-with-a-changing-input-dataset-each-time-without/m-p/595164#M171173</link>
      <description>&lt;P&gt;You can extract all the data set names in a library by using PROC SQL, and then either CALL EXECUTE or a macro will do the looping.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro do_all;
proc sql noprint;
    select memname into :dsnames separated by ' ' from dictionary.tables
        where upcase(libname)='UNIXWORK';
quit;

%do i=1 %to %sysfunc(countw(&amp;amp;dsnames));
    %let thisname=%scan(&amp;amp;dsnames,&amp;amp;i,%str( ));
    %forecast(data=unixwork.&amp;amp;thisname, ...)
%end;
%mend
%do_all&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Oct 2019 18:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-a-macro-with-a-changing-input-dataset-each-time-without/m-p/595164#M171173</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-09T18:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: Run a macro with a changing input dataset each time without having to specify the input dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-a-macro-with-a-changing-input-dataset-each-time-without/m-p/595173#M171174</link>
      <description>&lt;P&gt;Thank you. Worked perfect!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2019 19:18:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-a-macro-with-a-changing-input-dataset-each-time-without/m-p/595173#M171174</guid>
      <dc:creator>slottemc</dc:creator>
      <dc:date>2019-10-09T19:18:25Z</dc:date>
    </item>
    <item>
      <title>Re: Run a macro with a changing input dataset each time without having to specify the input dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-a-macro-with-a-changing-input-dataset-each-time-without/m-p/595174#M171175</link>
      <description>&lt;P&gt;CALL EXECUTE to run them all.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The documentation has an example or I have an example at the end of this tutorial&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FYI - make sure to uniquely name each output file.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/289891"&gt;@slottemc&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I want to run the below macro using &amp;amp;name as the input dataset, but I have over a hundred datasets I need to run this through. I originally wanted to do the macro as a by group but it does not look like it has that functionality and instead has to be run one at a time. What is the best way to change the input dataset names?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%forecast (data=unixwork.&amp;amp;name, var=rate, id=date, interval=month,
           project=projtest_fcb, entry=forecast, out=unixwork.forecast_fcb, 
           climit=95, horizon=4, keep=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The values of &amp;amp;name would be...&lt;/P&gt;
&lt;P&gt;1)BCS_CHMO&lt;/P&gt;
&lt;P&gt;2)BCS_CPPO&lt;/P&gt;
&lt;P&gt;3)BCS_XHMO&lt;/P&gt;
&lt;P&gt;4)COL_CHMO&lt;/P&gt;
&lt;P&gt;5)COL_CPPO&lt;/P&gt;
&lt;P&gt;6)CISDTP_XHMO&lt;/P&gt;
&lt;P&gt;7)PPC1_XPPO&lt;/P&gt;
&lt;P&gt;etc. like I said over 100 of these values&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had all of these in a KEY column in my original table, but then I split it all out into their own datasets, but now I think I didn't need to do that, but probably could have used some type of call symput or %Syscall set to change the value of &amp;amp;name and run the macro and keep doing until each &amp;amp;name is run?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data input;
input KEY product measure $ date rate;
datalines ;
BCS_CHMO     CHMO BCS    01JAN2016 .5432
BCS_CPPO     CPPO BCS    01JAN2016 .4567
BCS_XHMO     XHMO BCS    01JAN2016 .4321
COL_CHMO     CHMO COL    01JAN2016 .5678
COL_CPPO     CPPO COL    01JAN2016 .4567
CISDTP_XHMO  XHMO CISDTP 01JAN2016 .2345
PPC1_XPPO    XPPO PPC1   01JAN2016 .3210
;
data _null_;
 if _n_=1 then do;
   if 0 then set input;
   declare hash h(dataset:'input(obs=0)',multidata:'y');
   h.definekey(all:'y');
   h.definedata(all:'y');
   h.definedone();
 end;
do until(last.key);
 set input;
 by key;
 h.add();
end;
h.output(dataset:key);
h.clear();
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2019 19:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-a-macro-with-a-changing-input-dataset-each-time-without/m-p/595174#M171175</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-09T19:18:35Z</dc:date>
    </item>
  </channel>
</rss>

