<?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: How to execute a macro for each record in a sas dataset in parallel? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303288#M64401</link>
    <description>&lt;P&gt;Does your Country variable contain any names like New Guinea where there is a space imbedded in the name? Or are the values in your Country variable delimited by a special character between each name such as a comma or pipe?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If none contain spaces then&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    set controltable;
    by country;
    length cname $ 30 ;
    if first.country then do i = 1 to countw(country);
      cname = scan(country,i);
      call execute(cats('%test(',cname,')'));
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;may work. If you have a delimeter betwee names then that goes in the COUNTW and SCAN function calls.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want this line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where country = &amp;amp;country;&lt;/P&gt;
&lt;P&gt;to be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where index(country,"&amp;amp;country")&amp;gt;0;&lt;/P&gt;
&lt;P&gt;because other wise your single country in the call won't match the value with multple names in the country variable.&lt;/P&gt;</description>
    <pubDate>Fri, 07 Oct 2016 20:27:50 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-10-07T20:27:50Z</dc:date>
    <item>
      <title>How to execute a macro for each record in a sas dataset in parallel?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303283#M64397</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a control table which has a list of countries. I am calling a macro test for each value of the country using call execute function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the field country has three values , is it possible to modify the code so as to make three macro calls run in parallel?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro test(country);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data out_&amp;amp;country;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set dataset1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where country = &amp;amp;country;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;
&lt;P&gt;%mend test;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set controltable;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by country;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.country;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute(cats('%test(',country,')'));&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Sheeba&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2016 20:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303283#M64397</guid>
      <dc:creator>Sheeba</dc:creator>
      <dc:date>2016-10-07T20:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a macro for each record in a sas dataset in parallel?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303288#M64401</link>
      <description>&lt;P&gt;Does your Country variable contain any names like New Guinea where there is a space imbedded in the name? Or are the values in your Country variable delimited by a special character between each name such as a comma or pipe?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If none contain spaces then&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    set controltable;
    by country;
    length cname $ 30 ;
    if first.country then do i = 1 to countw(country);
      cname = scan(country,i);
      call execute(cats('%test(',cname,')'));
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;may work. If you have a delimeter betwee names then that goes in the COUNTW and SCAN function calls.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want this line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where country = &amp;amp;country;&lt;/P&gt;
&lt;P&gt;to be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where index(country,"&amp;amp;country")&amp;gt;0;&lt;/P&gt;
&lt;P&gt;because other wise your single country in the call won't match the value with multple names in the country variable.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2016 20:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303288#M64401</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-10-07T20:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a macro for each record in a sas dataset in parallel?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303298#M64405</link>
      <description>&lt;P&gt;It depends on what you are really after here. &amp;nbsp;If you want practice with CALL EXECUTE, that's one thing. &amp;nbsp;But if you just want to extract all the countries that match into one large data set, there are many ways to accomplish that. &amp;nbsp;Here's one (subject to debugging, since my SQL is not necessarily correct):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table selected_countries as select * from dataset1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; where country in (select country from control_table);&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2016 20:40:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303298#M64405</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-10-07T20:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a macro for each record in a sas dataset in parallel?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303324#M64415</link>
      <description>&lt;P&gt;Hi Ballardw,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sure . I will include the delimiter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for pointing out the index function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also if the values of the country are as follows&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;country&lt;/P&gt;
&lt;P&gt;country1&lt;/P&gt;
&lt;P&gt;country2&lt;/P&gt;
&lt;P&gt;country3&lt;/P&gt;
&lt;P&gt;country4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is there anyway i can call the macro for each record parallelly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;that is for each record can i make some modification to execute the macro for each record parallelly so as to reduce the time taken ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again,&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Sheeba&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2016 23:05:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303324#M64415</guid>
      <dc:creator>Sheeba</dc:creator>
      <dc:date>2016-10-07T23:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a macro for each record in a sas dataset in parallel?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303325#M64416</link>
      <description>&lt;P&gt;Hi Astounding,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am planning to try with call execute .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again for the suggestion.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Sheeba&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2016 23:09:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303325#M64416</guid>
      <dc:creator>Sheeba</dc:creator>
      <dc:date>2016-10-07T23:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a macro for each record in a sas dataset in parallel?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303334#M64418</link>
      <description>&lt;P&gt;&lt;EM&gt;is there anyway i can call the macro for each record parallelly.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;that is for each record can i make some modification to execute the macro for each record parallelly so as to reduce the time taken ?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have SAS/Connect licensed then you could run each table creation in a separate rsubmit block in parallel, but....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're really concerned about performance then the first thing you should do is to reduce passes through your large table. The way you've coded there would be a full pass through the large table for every single country.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below a code version where you get the same result with a single pass through your large table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data controltable;
  length country $ 10;
  do country='CANADA', 'EGYPT', 'GERMANY', 'MEXICO';
    output; output;
  end;
  stop;
run;

proc sql noprint;
  select 
    distinct catt('work.',country) 
      into :country_tbls separated by ' '
  from controltable
  ;

  select 
    distinct catt('when("',country,'") output work.',country,';') 
      into :country_selection separated by ' '
  from controltable
  ;
quit;

data &amp;amp;country_tbls;
  set sashelp.prdsale;

  select(country);
    &amp;amp;country_selection
    otherwise;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And last but not least: It's most of the time a sub-optimal design approach to split up a single data set into multiple data sets the way you're doing it. Most of the time it's much easier to keep the data "together" and use by group processing.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Oct 2016 03:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303334#M64418</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-10-08T03:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a macro for each record in a sas dataset in parallel?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303358#M64426</link>
      <description>&lt;P&gt;Rather than creating a macro that runs the analysis for one item, I'd rather use call execute to develop one analysis step that outputs the results in one pass:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call execute("data");
do until (eof1);
  set countries end=eof1;
  call execute(" country_"!!trim(country));
end;
call execute("; ");
do until (eof2);
  set countries end=eof2;
  call execute("/* analysis code for one country */; output country_"!!trim(country)!!"; ");
end;
call execute("run;");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(completely untested, of course)&lt;/P&gt;
&lt;P&gt;This would create a multiple of outputs in one scan through the original dataset.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Oct 2016 08:53:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303358#M64426</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-08T08:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a macro for each record in a sas dataset in parallel?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303589#M64514</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot for the detailed reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am new to SAS/connect. I will go through the details.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot for pointing out the passthrough. I will change and incorporate the below version/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Sheeba Swaminathan&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2016 16:20:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303589#M64514</guid>
      <dc:creator>Sheeba</dc:creator>
      <dc:date>2016-10-10T16:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a macro for each record in a sas dataset in parallel?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303593#M64516</link>
      <description>&lt;P&gt;Hi KurtBremser,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot for the reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will modify the code to include the changes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Sheeba&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2016 16:29:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-macro-for-each-record-in-a-sas-dataset-in/m-p/303593#M64516</guid>
      <dc:creator>Sheeba</dc:creator>
      <dc:date>2016-10-10T16:29:47Z</dc:date>
    </item>
  </channel>
</rss>

