<?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: Calling a macro using RSubmit in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/892023#M352366</link>
    <description>&lt;P&gt;Or the macro needs to be smart enough to generate the RSUBMIT/ENDRSUBMIT code itself.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test1(year,remote);
rsubmit &amp;amp;remote;
/* The rest of the macro definition goes here */
endrsubmit;
%mend;

signon worker1 inheritlib=(workdir) ;
signon worker2 inheritlib=(workdir) ;

%test1(&amp;amp;YEAR1.,worker1)
%test1(&amp;amp;year2,worker2)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 31 Aug 2023 17:56:09 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-08-31T17:56:09Z</dc:date>
    <item>
      <title>Calling a macro using RSubmit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/891988#M352353</link>
      <description>&lt;P&gt;I am working on a project that requires pulling several years of data.&amp;nbsp; I am doing a simplified test of how to use RSubmit and call a macro that can cycle through 2 year (my project requires 6 years), so they can run in parallel.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run this I get a log message that says:&amp;nbsp;&lt;/P&gt;&lt;P&gt;WARNING: Apparent invocation of macro TEST1 not resolved.&lt;/P&gt;&lt;P&gt;1 %TEST1(&amp;amp;YEAR2.);&lt;BR /&gt;-&lt;BR /&gt;180&lt;BR /&gt;&lt;BR /&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I pass the macro TEST1 through to each RSubmit?&amp;nbsp; Also, I assume that there will be issues calling YEAR1 and YEAR2. Thanks for the help!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;options autosignon=yes&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;noconnectwait&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;noconnectpersist&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;sascmd='!sascmd'&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;compress=yes;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%LET YEAR1 = 2021;&lt;/DIV&gt;&lt;DIV&gt;%LET YEAR2 = 2022;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;%MACRO TEST1(YEAR);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;PROC SQL;&lt;/DIV&gt;&lt;DIV&gt;CREATE TABLE workdir.CHECKTOTALS_&amp;amp;YEAR. AS SELECT&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;DATE_OF_SERVICE,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;SUM(Scripts) as Scripts&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;FROM SOURCE_TABLE&lt;/DIV&gt;&lt;DIV&gt;Where &lt;SPAN&gt;SERVICEMONTH &amp;gt;= &amp;amp;YEAR.01&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;and SERVICEMONTH &amp;lt;= &amp;amp;YEAR.12&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;GROUP BY 1&lt;/DIV&gt;&lt;DIV&gt;ORDER BY 1&lt;/DIV&gt;&lt;DIV&gt;;QUIT;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%MEND TEST1;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%syslput _USER_ / remote=worker1;&lt;/DIV&gt;&lt;DIV&gt;%syslput _USER_ / remote=worker2;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;libname workdir "%sysfunc(getoption(work))";&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;rsubmit inheritlib=(workdir) remote=worker1;&lt;/DIV&gt;&lt;DIV&gt;%TEST1(&amp;amp;YEAR1.);&lt;/DIV&gt;&lt;DIV&gt;ENDRSUBMIT;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;rsubmit inheritlib=(workdir) remote=worker2;&lt;/DIV&gt;&lt;DIV&gt;%TEST1(&amp;amp;YEAR2.);&lt;/DIV&gt;&lt;DIV&gt;ENDRSUBMIT;&lt;/DIV&gt;</description>
      <pubDate>Thu, 31 Aug 2023 16:28:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/891988#M352353</guid>
      <dc:creator>Philmingo</dc:creator>
      <dc:date>2023-08-31T16:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro using RSubmit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/891995#M352356</link>
      <description>&lt;P&gt;The macro must be defined on the remote machine&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rsubmit inheritlib=(workdir) remote=worker1;
%macro test1(year);
/* The rest of the macro definition goes here */
%mend;
%TEST1(&amp;amp;YEAR1.)
ENDRSUBMIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Aug 2023 16:50:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/891995#M352356</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-31T16:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro using RSubmit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/892022#M352365</link>
      <description>&lt;P&gt;That solution would require me to write the same macro within each RSubmit statement for each worker.&amp;nbsp; Is that correct?&amp;nbsp; I am looking for a solution that allows me to write the macro once and call that macro and its variables within each of the RSubmits.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 17:53:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/892022#M352365</guid>
      <dc:creator>Philmingo</dc:creator>
      <dc:date>2023-08-31T17:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro using RSubmit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/892023#M352366</link>
      <description>&lt;P&gt;Or the macro needs to be smart enough to generate the RSUBMIT/ENDRSUBMIT code itself.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test1(year,remote);
rsubmit &amp;amp;remote;
/* The rest of the macro definition goes here */
endrsubmit;
%mend;

signon worker1 inheritlib=(workdir) ;
signon worker2 inheritlib=(workdir) ;

%test1(&amp;amp;YEAR1.,worker1)
%test1(&amp;amp;year2,worker2)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 17:56:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/892023#M352366</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-31T17:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro using RSubmit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/892024#M352367</link>
      <description>&lt;P&gt;Looks like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;has beaten me to it, but I think he has the answer.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 17:57:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/892024#M352367</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-31T17:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro using RSubmit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/892032#M352371</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/117987"&gt;@Philmingo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;That solution would require me to write the same macro within each RSubmit statement for each worker.&amp;nbsp; Is that correct?&amp;nbsp; I am looking for a solution that allows me to write the macro once and call that macro and its variables within each of the RSubmits.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just place the file with the macro definition where each "worker" can see it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rsubmit worker1;
%include '~/test1.sas';
%test1;
endrsubmit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the remote sessions are on other machines then upload the source file and then include it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rsubmit worker1;
filename mycopy temp;
proc upload infile='~/test1.sas' outfile=mycopy status=n; 
run;
%include mycopy;
%test1;
endrsubmit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Aug 2023 18:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/892032#M352371</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-31T18:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro using RSubmit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/892056#M352385</link>
      <description>&lt;P&gt;I tried taking this approach but this has presented new warning and error messages.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;%LET YEAR1 = 2021;&lt;BR /&gt;%LET YEAR2 = 2022;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%MACRO TEST1(YEAR, WORKER);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;libname workdir "%sysfunc(getoption(work))";&lt;/DIV&gt;&lt;DIV&gt;rsubmit inheritlib=(workdir) remote=&amp;amp;worker.;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;PROC SQL;&lt;/DIV&gt;&lt;DIV&gt;CREATE TABLE workdir.CHECKTOTALS_&amp;amp;YEAR. AS SELECT&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;DATE_OF_SERVICE,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;SUM(Script_Cnt) as Scripts,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;SUM(Allowed) as Allowed&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;FROM SOURCE_TABLE&lt;/DIV&gt;&lt;DIV&gt;Where claim_status = 'P'&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;and substr(CMS_PLAN_ID, 1,1) IN('H', 'R', 'S')&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;and SERVICEMONTH &amp;gt;= &amp;amp;YEAR.01&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;and SERVICEMONTH &amp;lt;= &amp;amp;YEAR.12&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;GROUP BY 1&lt;/DIV&gt;&lt;DIV&gt;ORDER BY 1&lt;/DIV&gt;&lt;DIV&gt;;QUIT;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;ENDRSUBMIT;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%MEND TEST1;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;SIGNON WORKER1 INHERITLIB = (WORKDIR);&lt;/DIV&gt;&lt;DIV&gt;SIGNON WORKER2 INHERITLIB = (WORKDIR);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%TEST1(&amp;amp;YEAR1., worker1);&lt;/DIV&gt;&lt;DIV&gt;%TEST1(&amp;amp;YEAR2., worker2);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Warning &amp;amp; Error Messages:&lt;/DIV&gt;&lt;DIV&gt;WARNING: Apparent symbolic reference YEAR not resolved.&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: (, AS, LIKE.&lt;BR /&gt;&lt;BR /&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/DIV&gt;</description>
      <pubDate>Thu, 31 Aug 2023 19:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/892056#M352385</guid>
      <dc:creator>Philmingo</dc:creator>
      <dc:date>2023-08-31T19:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro using RSubmit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/892135#M352387</link>
      <description>&lt;P&gt;If you want the remote code to reference a macro variable named YEAR you have to create it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO TEST1(YEAR, WORKER);
%syslput year=&amp;amp;year /remote=&amp;amp;worker;
&lt;BR /&gt;rsubmit inheritlib=(work=workdir) remote=&amp;amp;worker.;

PROC SQL;
CREATE TABLE workdir.CHECKTOTALS_&amp;amp;YEAR. AS SELECT 
DATE_OF_SERVICE,
SUM(Script_Cnt) as Scripts,
SUM(Allowed) as Allowed
FROM SOURCE_TABLE
Where claim_status = 'P' 
and substr(CMS_PLAN_ID, 1,1) IN('H', 'R', 'S')
and SERVICEMONTH &amp;gt;= &amp;amp;YEAR.01 
and SERVICEMONTH &amp;lt;= &amp;amp;YEAR.12
GROUP BY 1
ORDER BY 1
;QUIT;
 
ENDRSUBMIT;
 
%MEND TEST1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which means the remote session has to exist BEFORE the RSUBMIT statement (ie you cannot use the RSUBMIT statement to create the remote session).&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 20:02:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/892135#M352387</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-31T20:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro using RSubmit</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/892138#M352389</link>
      <description>&lt;P&gt;That's because macro variables YEAR1 and YEAR2 are only defined in your parent SAS session and not in the RSUBMIT or child session.&lt;/P&gt;
&lt;P&gt;Add this statement after signing on to copy your macro variables over to the new session:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%syslput _all_ / remote = &amp;amp;worker;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Aug 2023 20:04:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro-using-RSubmit/m-p/892138#M352389</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-08-31T20:04:35Z</dc:date>
    </item>
  </channel>
</rss>

