<?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: Splitting and applying macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Splitting-and-applying-macros/m-p/346310#M79837</link>
    <description>&lt;P&gt;Are you macros functioning individually?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 31 Mar 2017 19:42:03 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-03-31T19:42:03Z</dc:date>
    <item>
      <title>Splitting and applying macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-and-applying-macros/m-p/346279#M79826</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Duplication-in-parallel/m-p/345837#M79632" target="_self"&gt;As asked in my post yesterday&lt;/A&gt;, I would like to duplicate each row of a big table A in a table B before reducing B in a table C, and it's technically impossible currently to duplicate, too big volume of data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I noticed that if I split A into parts (1000 rows per part), then I apply the duplication on a part, and then reduce the part before duplicating the next part, it can work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to do:&lt;/P&gt;&lt;P&gt;1/ Splitting A into A1, A2,...An&lt;/P&gt;&lt;P&gt;2/ Duplicate A1 into B1. Reduce B1 into C1. Delete B1&lt;/P&gt;&lt;P&gt;3/ Duplicate A2 into B2. Reduce B2 into C2. Delete B2&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;n+1/ Duplicate An into Bn. Reduce Bn into Cn. Delete Bn&lt;/P&gt;&lt;P&gt;n+2/ Make an union of all Ci tables into C&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But technically I don't arrive to split into 1000 rows tables and applying my duplication macro, and my reduction macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's say that:&lt;/P&gt;&lt;P&gt;- my duplication macro is called "duplication(i)" use Ai and output&amp;nbsp;my table Bi,&lt;/P&gt;&lt;P&gt;- my reducing macro is called "reduce(i)", use Bi and output Ci&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro getpartextraction(part= 0);
PROC SQL;
CREATE TABLE A&amp;amp;part AS
SELECT * FROM A
WHERE ID_ROW &amp;gt;= (&amp;amp;part-1)*1000+1 AND ID_ROW &amp;lt;= MIN(MAX(ID_ROW), &amp;amp;part*1000)
ORDER BY ID_ROW;
%mend;

data _null_;
set A;

do k = 1 to (MAX(ID_ROW)/1000);
		call execute('%getpartextraction('||k||')');&lt;BR /&gt;                call execute('%duplication('||k||')');&lt;BR /&gt;                call execute('%reduce('||k||')');
end; 
run;

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the moment I try to split A to Ai but there is an error&lt;/P&gt;&lt;P&gt;"an error occured executing the workspace "Duplication process". The server is disconnected. "&lt;/P&gt;&lt;P&gt;And "Duplication process" is the name of my programm. I need to rerun everything after this error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know where is the problem?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: ID_ROW is the number of the row in the big table A&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 18:44:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-and-applying-macros/m-p/346279#M79826</guid>
      <dc:creator>Planck</dc:creator>
      <dc:date>2017-03-31T18:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting and applying macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-and-applying-macros/m-p/346310#M79837</link>
      <description>&lt;P&gt;Are you macros functioning individually?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 19:42:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-and-applying-macros/m-p/346310#M79837</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-31T19:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting and applying macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-and-applying-macros/m-p/346320#M79843</link>
      <description>&lt;P&gt;When you get unusual results form macros it is a good idea to attempt the code with some of the macro debug options turned on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Options Mprint symbolgen;&lt;/P&gt;
&lt;P&gt;will add generated code to the log and descriptions of resolving macro variables which may point to something.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I were working in a server environment a message like that would make think of a network bottleneck or possibly exceeding the amount of work space you have available on the server.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks as if you are calling those 3 macros mulitple times for each record in a with the exact same parameter value of 'k'. So you may have stacked up a bunch of identical calls and just plain overloaded everything. Note that&amp;nbsp; your code max(Id_row) in the data _null_ step is exactly the same as Id_row as the variable Id_row is only one variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without code for the macros your are calling it is hard to make suggestions as to where to look to likely causes though I would recommend running the macro duplication with manual parameters a time or two.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 19:58:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-and-applying-macros/m-p/346320#M79843</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-31T19:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting and applying macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-and-applying-macros/m-p/346323#M79846</link>
      <description>&lt;P&gt;Yes they are working well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Iam trying this:&lt;/P&gt;&lt;PRE&gt;macro getpartextraction(part =);
PROC SQL;
CREATE TABLE A&amp;amp;part AS
SELECT * FROM A
WHERE ID_ROW&amp;gt;= (&amp;amp;part-1)*1000+1 AND ID_ROW&amp;lt;= &amp;amp;part*1000
ORDER BY ID_ROW;
%mend;

data _null_;
set A;
call execute('%getpartextraction(part='||1||')');
run;&lt;/PRE&gt;&lt;P&gt;And even this is not working...&lt;/P&gt;&lt;P&gt;It is running since ages without answering my query...&lt;/P&gt;&lt;P&gt;Whereas it is the same code than this:&lt;/P&gt;&lt;PRE&gt;PROC SQL;
CREATE TABLE A1 AS
SELECT * FROM A
WHERE ID_ROW&amp;gt;= 1 AND ID_ROW&amp;lt;= 1000
ORDER BY ID_ROW;&lt;/PRE&gt;&lt;P&gt;That's a nonsense...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: I finally had the good answer in 30 minutes...lol&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 20:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-and-applying-macros/m-p/346323#M79846</guid>
      <dc:creator>Planck</dc:creator>
      <dc:date>2017-03-31T20:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting and applying macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-and-applying-macros/m-p/346326#M79848</link>
      <description>&lt;P&gt;Thanks for your answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;But I will look at my macros after.&lt;/P&gt;&lt;P&gt;There is obviously a problem with my split (see my previous post).&lt;/P&gt;&lt;P&gt;Do you see why it was so long to run it?&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 20:09:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-and-applying-macros/m-p/346326#M79848</guid>
      <dc:creator>Planck</dc:creator>
      <dc:date>2017-03-31T20:09:03Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting and applying macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-and-applying-macros/m-p/346329#M79850</link>
      <description>&lt;P&gt;Why are you using PROC SQL? Is your data not in SAS datasets?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro getpartextraction(dsn=A, part= 0,size=1000);
data &amp;amp;dsn.&amp;amp;part ;
  set &amp;amp;dsn (firstobs=%eval((&amp;amp;size * &amp;amp;part) +1) obs=%eval(&amp;amp;size*(&amp;amp;part+1)) );
run;
%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now generate a call each ;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  set A nobs=nobs ;
  file code ;
  do part=0 to int(nobs/1000);
     put '%getpartextraction(dsn=A,size=1000,' part = ')' ;
  end;
  stop;
run;
%include code / source2 ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 Mar 2017 20:12:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-and-applying-macros/m-p/346329#M79850</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-03-31T20:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting and applying macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-and-applying-macros/m-p/346342#M79858</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/121074"&gt;@Planck&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;But I will look at my macros after.&lt;/P&gt;
&lt;P&gt;There is obviously a problem with my split (see my previous post).&lt;/P&gt;
&lt;P&gt;Do you see why it was so long to run it?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you make the same call to the three macros multiple times with the same K then you are just doing the same step over and over with the exact same values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Again you have not shared any actual data. HOW many records are in your dataset A? Your data _null_ step attempts to&amp;nbsp;call those macros for &lt;STRONG&gt;every single record&lt;/STRONG&gt; in that data set. Since you apparently have several thousands of records &lt;STRONG&gt;in A&lt;/STRONG&gt; then you are calling the do loop 1000s of times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HOWEVER sind you have MAX(Id_Row) the the data _null_step does not even execute because you only have one argument and MAX requires at least 2 in a data step. So I don't really see how you are getting the error at all.&lt;/P&gt;
&lt;P&gt;So some code must be missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And as we say: showing a log really helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 21:15:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-and-applying-macros/m-p/346342#M79858</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-31T21:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting and applying macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-and-applying-macros/m-p/346596#M79950</link>
      <description>&lt;P&gt;Thanks it was exactly what I needed&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2017 08:19:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-and-applying-macros/m-p/346596#M79950</guid>
      <dc:creator>Planck</dc:creator>
      <dc:date>2017-04-03T08:19:16Z</dc:date>
    </item>
  </channel>
</rss>

