<?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: Data driven macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-driven-macro/m-p/705004#M216172</link>
    <description>&lt;P&gt;First, correct your macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro queries(ctagl, fecq1, fecspro);
  proc sql;
  select * from table1
  where eoddate = &amp;amp;fecq1 and acctfrom = &amp;amp;ctagl;
  /* single quotes prevent resolution of macro triggers */
  /* if acctfrom is character, add double quotes around &amp;amp;ctagl */
  quit;

  proc sql;
  select * from table2
  where anio = year(&amp;amp;fecspro) and mes = month(&amp;amp;fecspro) and dia = day(&amp;amp;fecspro)
  and ctagl = &amp;amp;ctagl;
  quit;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then, to call your macro from the input_table, use CALL EXECUTE in a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set input_table;
call execute(cats('%nrstr(%queries(',account_number,',',date1,',',date2,'))'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or write the calls to a temporary file and include that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename inc_file temp;

data _null_;
set input_table;
file inc_file;
string = cats('%queries(',account_number,',',date1,',',date2,')');
put string;
run;

%include inc_file;

filename inc_file;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 10 Dec 2020 09:44:31 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-12-10T09:44:31Z</dc:date>
    <item>
      <title>Data driven macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-driven-macro/m-p/704983#M216160</link>
      <description>&lt;P&gt;Hi all, I have this project in mind but not sure how to complete it...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an "input table" like this:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;account_number&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Date1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Date2&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;01/dec/2020&lt;/TD&gt;&lt;TD&gt;02/dec/2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;02/dec/2020&lt;/TD&gt;&lt;TD&gt;03/dec/2020&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create a macro which iterates every record from the "input table" and use every value from every field as a filter in two proc sql, the code I had is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro queries(ctagl, fecq1, fecspro);
	proc sql;
	select * from table1
	where eoddate = '&amp;amp;fecq1' and acctfrom = '&amp;amp;ctagl';
	quit;
	
	proc sql;
	select * from table2
	where anio = year(&amp;amp;fecspro) and mes = month(&amp;amp;fecspro) and dia = day(&amp;amp;fecspro)
	and ctagl = &amp;amp;ctagl;
	quit;
	
%mend;


%macro execute_queries

	%do %until eof(input_table);
		
		%macro queries(account_number, Date1, Date2);
	
	%end;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm not sure if &lt;EM&gt;%do %until&lt;/EM&gt; works with &lt;EM&gt;eof&lt;/EM&gt; (I had used before without the macro) or is another way to go through input_table using macro code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fernando&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 08:45:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-driven-macro/m-p/704983#M216160</guid>
      <dc:creator>japfvg</dc:creator>
      <dc:date>2020-12-10T08:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: Data driven macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-driven-macro/m-p/705004#M216172</link>
      <description>&lt;P&gt;First, correct your macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro queries(ctagl, fecq1, fecspro);
  proc sql;
  select * from table1
  where eoddate = &amp;amp;fecq1 and acctfrom = &amp;amp;ctagl;
  /* single quotes prevent resolution of macro triggers */
  /* if acctfrom is character, add double quotes around &amp;amp;ctagl */
  quit;

  proc sql;
  select * from table2
  where anio = year(&amp;amp;fecspro) and mes = month(&amp;amp;fecspro) and dia = day(&amp;amp;fecspro)
  and ctagl = &amp;amp;ctagl;
  quit;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then, to call your macro from the input_table, use CALL EXECUTE in a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set input_table;
call execute(cats('%nrstr(%queries(',account_number,',',date1,',',date2,'))'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or write the calls to a temporary file and include that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename inc_file temp;

data _null_;
set input_table;
file inc_file;
string = cats('%queries(',account_number,',',date1,',',date2,')');
put string;
run;

%include inc_file;

filename inc_file;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Dec 2020 09:44:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-driven-macro/m-p/705004#M216172</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-10T09:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Data driven macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-driven-macro/m-p/705005#M216173</link>
      <description>&lt;P&gt;No need for a macro. Try something like this (untested as no data was provided):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set TABLE;
  call execute( 'proc sql;'
              ||'select * from TABLE '
              ||'where EODDATE  =' || DATE1 
              ||'  and ACCTFROM =' || quote(trim(ACCOUNT_NUMBER))
              ||'; quit;' );
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 09:47:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-driven-macro/m-p/705005#M216173</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-12-10T09:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: Data driven macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-driven-macro/m-p/705007#M216174</link>
      <description>&lt;P&gt;1) To execute a macro use (in your case) &lt;STRONG&gt;%queries&lt;/STRONG&gt;&amp;nbsp;and not "%macro queries(...)&lt;/P&gt;
&lt;P&gt;2) You don't need the second macro "execute_queries" as it can be done in a data step&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;using&amp;nbsp;&lt;STRONG&gt;call execute()&amp;nbsp;&lt;/STRONG&gt; function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;lt;output&amp;gt;;
 set input_table;
      cmd = catx("," , "%queries(", account_number,Date1,Date2, ")");
      call execute(cmd);
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3) Running "proc sql; select ..." will write the output to the "output" window or "result" tab,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;depending on sas platform you use.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; You should define what kind f final output you want. either a dataset or a report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 09:47:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-driven-macro/m-p/705007#M216174</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-12-10T09:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: Data driven macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-driven-macro/m-p/705083#M216213</link>
      <description>&lt;P&gt;Thanks a lot for your quick answers!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll try with call_execute command.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a great day everyone!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fer&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 15:01:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-driven-macro/m-p/705083#M216213</guid>
      <dc:creator>japfvg</dc:creator>
      <dc:date>2020-12-10T15:01:59Z</dc:date>
    </item>
  </channel>
</rss>

