<?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: Call Execute a macro from data statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Call-Execute-a-macro-from-data-statement/m-p/514330#M138690</link>
    <description>&lt;P&gt;Your macro is only generating part of a data step.&amp;nbsp; You either need to generate the rest of the data step with other CALL EXECUTE() statements or add those lines to your macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you are running this step&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set mgm_runs;
call execute('%Run_MGM('||mgmwb||','||trim(cp_name)||','||trim(schedule)||','||startage||','||startyear||')');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It will push code onto the stack to run after it finishes.&amp;nbsp; The first couple of lines your macro call generates are assignment statements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   script   = catx('\',pathname('WORK'),'MGM_RUN.vbs');
   filevar  = script;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You cannot just run an assignment statement like that without first starting a data step.&amp;nbsp; So you will need to at least a DATA statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Why not just add these two lines to your macro. One at the top and one at the bottom. So that your macro is now generating a complete data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 19 Nov 2018 03:39:05 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-11-19T03:39:05Z</dc:date>
    <item>
      <title>Call Execute a macro from data statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-Execute-a-macro-from-data-statement/m-p/514328#M138689</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to execute a macro that builds a temporary VBS script based on some parameters stored in the data table. 3 lines, 3 executions. I am getting:&amp;nbsp;ERROR 180-322: Statement is not valid or it is used out of proper&amp;nbsp;order.&lt;/P&gt;
&lt;P&gt;Can you please help!&lt;/P&gt;
&lt;P&gt;TIA&lt;/P&gt;
&lt;P&gt;GG&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*output*/ filename txtout   "C:\Documents and Settings\&amp;amp;sysuserid\My Documents";
/*input*/ filename ylds   "C:\Documents and Settings\&amp;amp;sysuserid\My Documents\yields.csv";
libname sasds "H:\SASWork\MGM_BATCH\data\sasds";

%macro Run_MGM(mgmfile,cp,sched,startage,startyr);
   script   = catx('\',pathname('WORK'),'MGM_RUN.vbs');
   filevar  = script;
   /* write the script */
   file dummy1 filevar=filevar;

   put "Const workbook=""&amp;amp;mgmfile.""";
   put "Const txtout=""C:\Documents and Settings\&amp;amp;sysuserid.\My Documents""";
   put "Const xlCSV = 6";
   put 'Set objExcel = CreateObject("Excel.Application")';
   put 'With objExcel';
   put +3 '.Visible = False';
   put +3 'Set objWorkbook  = .Workbooks.Open(workbook)';
   put +3 'objWorkbook.Close';
   put +3 '.Application.Quit';
   put 'End With';

   /* close the script file by opening another, not used */
   filevar = catx('\',pathname('WORK'),'DUMMY.vbs');
   file dummy1 filevar=filevar;
   /* look at the script, not necessary but may be useful */
   infile dummy2 filevar=script end=eof;
   do while(not eof);
      input;
      putlog _infile_;
   end;
   /* call the script */
   command = catx(' ','cscript',quote(strip(script)),'//nologo');
   infile dummy3 pipe filevar=command end=eof truncover;
%mend Run_MGM ;

data mgm_runs;
set sasds.mgm_runs;
if runid gt 0;
mgmwb=trim(mgm_wb_path) || "\" || trim(mgm_wb_name);
run;

data _null_;
set mgm_runs;
call execute('%Run_MGM('||mgmwb||','||trim(cp_name)||','||trim(schedule)||','||startage||','||startyear||')');
run;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Nov 2018 03:20:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-Execute-a-macro-from-data-statement/m-p/514328#M138689</guid>
      <dc:creator>thexlwiz</dc:creator>
      <dc:date>2018-11-19T03:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: Call Execute a macro from data statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-Execute-a-macro-from-data-statement/m-p/514330#M138690</link>
      <description>&lt;P&gt;Your macro is only generating part of a data step.&amp;nbsp; You either need to generate the rest of the data step with other CALL EXECUTE() statements or add those lines to your macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you are running this step&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set mgm_runs;
call execute('%Run_MGM('||mgmwb||','||trim(cp_name)||','||trim(schedule)||','||startage||','||startyear||')');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It will push code onto the stack to run after it finishes.&amp;nbsp; The first couple of lines your macro call generates are assignment statements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   script   = catx('\',pathname('WORK'),'MGM_RUN.vbs');
   filevar  = script;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You cannot just run an assignment statement like that without first starting a data step.&amp;nbsp; So you will need to at least a DATA statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Why not just add these two lines to your macro. One at the top and one at the bottom. So that your macro is now generating a complete data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2018 03:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-Execute-a-macro-from-data-statement/m-p/514330#M138690</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-19T03:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: Call Execute a macro from data statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-Execute-a-macro-from-data-statement/m-p/514337#M138694</link>
      <description>&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2018 04:59:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-Execute-a-macro-from-data-statement/m-p/514337#M138694</guid>
      <dc:creator>thexlwiz</dc:creator>
      <dc:date>2018-11-19T04:59:26Z</dc:date>
    </item>
  </channel>
</rss>

