<?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: SAS crashes, using a macro in a data step because of memory in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570201#M160774</link>
    <description>&lt;P&gt;Seems like a lot of effort when you can just use %NRSTR() to prevent SAS from generating too many lines of code.&lt;/P&gt;
&lt;P&gt;Because the macro doesn't use parameters you need also protect the setting of the macro variables so that they execute in the right order also.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats('%nrstr(%let) taq_day=',ric_date,';'));
call execute(cats('%nrstr(%let) Mkt_day=',AXJO_date,';'));
call execute('%nrstr(%HFEQ_ALL);');
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or just write the code to a file instead of using CALL EXECUTE.&lt;/P&gt;</description>
    <pubDate>Mon, 01 Jul 2019 12:34:32 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-07-01T12:34:32Z</dc:date>
    <item>
      <title>SAS crashes, using a macro in a data step because of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570091#M160722</link>
      <description>&lt;P&gt;I am processing a big data and during the processing a lot of data sets will be created that are not required for the results. They are required for the calculations.&lt;BR /&gt;&lt;BR /&gt;Because of I/O speed limitation (and storage limitation) I have broke the data into smaller chunks. And to improve speed I have defined a library on the memory using memlib.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use a data step and call execute to run a macro on each chunk of data. The datasets required for calculations require roughly 100MB, and will be replaced in each iteration.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is SAS will crashes when I run the data step. I am sure it is not because of the datasets storage.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I tested by limiting the observations in data step (i.e. iterations ), when I put obs=25 on average SAS uses 140MB of memory. when obs=200 it uses the 1.2GB and if it is above 200 it will crash.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I run the code for 25 steps in each data step up to 300 and it just uses 140 MB. So it is not the datasets on the memory. But when I put obs=300 memory usage goes up above 1.2GB at the early stage just a seconds and SAS crashes and closes.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I suspect SAS do not know how much the macro uses the memory, so it buffer the data base on the data set and when starts the macro it will crash.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I couldn't solve the problem by BUFSIZE, or BUFFNO.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_  ; set ric_date(obs=200);

call symput('taq_day', ric_date); 

***;
AXJO_date =  catt( 'Mkt_' ,substr(ric_date, index( ric_date, '_') +1));

call symput('Mkt_day', AXJO_date);


****;

if substr(ric_date, index( ric_date, '_') +1) = substr(AXJO_date, index( ric_date, '_') +1) then

  call execute('%HFEQ_ALL');

/*%HFEQ_ALL*/
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jun 2019 11:14:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570091#M160722</guid>
      <dc:creator>Afshin</dc:creator>
      <dc:date>2019-06-30T11:14:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS crashes, using a macro in a data step because of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570097#M160725</link>
      <description>Your sample program calls the macro 200 times (not just.once for a chunk of 200 observations).  If you want help restructuring the program, you will have to supply details of what the macro is supposed to accomplish.</description>
      <pubDate>Sun, 30 Jun 2019 12:40:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570097#M160725</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-06-30T12:40:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS crashes, using a macro in a data step because of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570098#M160726</link>
      <description>&lt;P&gt;Thanks. The Data step is just for input the name of datasets into the macro. The macro is 800 line code with several datasteps and procs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I put some part of it as example. But the puzzle is that if run the data step with 100 obs each time (100 time running the macro), it does not fill the mmory but when I put obs=max it fills the memory and crashes.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;the mem library is on the memory.&amp;nbsp;&lt;BR /&gt;each step of macro does not need more than 100MB for the datasets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;at the end of the macro I move them to dataset on the storage and they will replaced in the next macro call.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro HFEQ_ALL;


	Data mem.taq; set split.&amp;amp;taq_day; run;
	data mem.indices; set split.&amp;amp;Mkt_day; run;

	data mem.markers ; set mem.taq;
		if first.date; 
								
		%do i=((10*60*60)+(15)) %to ((16*60*60)); 
			miliseconds=&amp;amp;i*1000; output; 
		%end;
	run;

...
...
...
...

data HFAT.HFT; set HFAT.HFT mem.HFT; run;
data HFAT.spreads; set HFAT.spreads mem.spreads; run;
data HFAT.inefficiencyMetrics; set HFAT.inefficiencyMetrics mem.inefficiencyMetrics; run;



%mend HFEQ_ALL;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jun 2019 12:56:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570098#M160726</guid>
      <dc:creator>Afshin</dc:creator>
      <dc:date>2019-06-30T12:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: SAS crashes, using a macro in a data step because of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570100#M160727</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/279907"&gt;@Afshin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From what you describe memory doesn't get released as you expect.&lt;/P&gt;
&lt;P&gt;One way to go: Assign and clear your memlib within the macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro HFEQ_ALL;
  libname mem '&amp;lt;your path&amp;gt;' memlib;
  .....
  libname mem clear;
%mend HFEQ_ALL;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And just as a side note:&lt;/P&gt;
&lt;P&gt;When calling a macro without brackets for parameter passing (even if empty) then I'd always end the call with a semicolon like done below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute('%HFEQ_ALL;');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jun 2019 14:10:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570100#M160727</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-06-30T14:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: SAS crashes, using a macro in a data step because of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570102#M160728</link>
      <description>&lt;P&gt;the memory won't release but it is replacing by new data set. Just to make sure I added the " mem clear" and didn't work.&lt;BR /&gt;&lt;BR /&gt;I dont think the datasets on memory are problem. The code works fine when I run 200 observation each time. for examle 1-200, 200-400, 400-600 ... and the momory usage by sas stays around 1.2GB.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;when I put obs=max which is milions observation. in couple of seconds it crashes, not after many steps.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;To make it clear:&amp;nbsp;&lt;BR /&gt;&lt;STRONG&gt;Observations&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SAS memory usage in task manager&lt;/STRONG&gt;&lt;BR /&gt;firstobs=1 obs=25&amp;nbsp; ---&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 250 MB&amp;nbsp; &amp;nbsp; ( constant during the process)&lt;/P&gt;&lt;P&gt;firstobs=26 obs=50&amp;nbsp; ---&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 250 MB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;~&lt;/P&gt;&lt;P&gt;firstobs=51 obs=75&amp;nbsp; ---&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 250 MB&lt;/P&gt;&lt;P&gt;firstobs=76 obs=100&amp;nbsp; ---&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 250 MB&lt;/P&gt;&lt;P&gt;firstobs=101 obs=125&amp;nbsp; ---&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 250 MB&lt;/P&gt;&lt;P&gt;firstobs=126 obs=150&amp;nbsp; ---&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 250 MB&lt;/P&gt;&lt;P&gt;firstobs=151 obs=175 ---&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 250 MB&lt;/P&gt;&lt;P&gt;firstobs=176 obs=200&amp;nbsp; ---&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 250 MB&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;firstobs=1 obs=200&amp;nbsp; ---&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1.2GB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (Constant during the process)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;firstobs=1 obs=max&amp;nbsp; ---&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; goes above&amp;nbsp; 1.2GB&amp;nbsp; &amp;nbsp;and crashes in couple of seconds- crash in first data step&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jun 2019 14:21:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570102#M160728</guid>
      <dc:creator>Afshin</dc:creator>
      <dc:date>2019-06-30T14:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: SAS crashes, using a macro in a data step because of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570103#M160729</link>
      <description>&lt;P&gt;How many lines of SAS code does that macro generate everytime you call it?&lt;/P&gt;
&lt;P&gt;Why are you pushing the resulting code into the program stack over 200 times instead of just pushing the macro call?&lt;/P&gt;
&lt;P&gt;I am not sure where SAS stores that stack of code that is waiting to run after the data step with the CALL EXECUTE() function calls finishes, but perhaps it is in memory and so perhaps that is what is causing the crash.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute('%nrstr(%HFEQ_ALL);');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also, just as a side issue, why not define the macro to take TAG_DAY and MKT_DAY as parameters instead of having it assume that those macro variables already exist when the macro starts?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also just write the lines of code to a file and %INCLUDE the file instead of using CALL EXECUTE().&amp;nbsp; Then you can take advantage of the PUT statement to help generate the code you want to run.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro HFEQ_ALL(taq_day,Mkt_day);
...
%mend;

filename code temp;
data _null_  ; 
  set ric_date ;
  taq_day=ric_date;
  AXJO_date =  catt( 'Mkt_' ,substr(taq_day, index( taq_day, '_') +1));
  if substr(taq_day, index( taq_day, '_') +1)
   = substr(AXJO_date, index( taq_day, '_') +1) then do;
    put '%HFEQ_ALL(' taq_day= ',' AXJO_date= ')' ;
  end;
run;
%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS the test in your IF condition does not make sense to me. Didn't you just set the end of AXJO_DATE with the end of TAQ_DAY (ric_date)?&amp;nbsp; How could they get to be different? You don't seem to have defined a length for the string AXJO_DATE are you testing if the value got truncated?&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jun 2019 14:49:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570103#M160729</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-30T14:49:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS crashes, using a macro in a data step because of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570104#M160730</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/279907"&gt;@Afshin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;......&lt;/P&gt;
&lt;P&gt;firstobs=1 obs=200&amp;nbsp; ---&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1.2GB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (Constant during the process)&lt;/P&gt;
&lt;P&gt;firstobs=1 obs=max&amp;nbsp; ---&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; goes above&amp;nbsp; 1.2GB&amp;nbsp; &amp;nbsp;and crashes in couple of seconds- crash in first data step&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ah, o.k., then you've got simply not enough memory available for what you're trying to do. If already a limitation of 200 obs takes you to 1.2GB of memory consumption then I don't believe there will be another way than to either keep your tables on disk or then to fully re-design your code so that it consumes much less memory and you only load the data into memory which you need for processing.&lt;/P&gt;
&lt;P&gt;It's also not so that loading data into memory always speeds up processing. For example your first data steps loading the data from disk into memory also take time - time you could already use for data step processing in the same data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To see what's available to you you can execute:&lt;/P&gt;
&lt;P&gt;proc options group=memory;run;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jun 2019 15:02:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570104#M160730</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-06-30T15:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: SAS crashes, using a macro in a data step because of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570117#M160734</link>
      <description>&lt;P&gt;It seems pretty clear that the memory problems result from stacking up too much code.&amp;nbsp; Some of the proposed solutions contain pitfalls and without getting into the pitfalls, here is a way to run all the macro calls accurately without having to break up the data into chunks:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro run_all;
   %local i nobs taq_day mkt_day run_flag;
   data _null_;   
      set ric_date nobs=_nobs_;
      call symputx('nobs', _nobs_);
      stop;
   run;

   %do i=1 %to &amp;amp;nobs;   
      %let run_flag = N;
     data _null_  ;
          i = &amp;amp;i;
         set ric_date point=i;
        call symputx('taq_day', ric_date); 
***;
        AXJO_date =  catt( 'Mkt_' ,substr(ric_date, index( ric_date, '_') +1));
        call symputx('Mkt_day', AXJO_date);
****;
        if substr(ric_date, index( ric_date, '_') +1) = 
        substr(AXJO_date, index( ric_date, '_') +1) then
        call call symputx('run_flag', 'Y');
       stop;
   run;

      %if &amp;amp;run_flag=Y %then %HFEQ_ALL;  
   %end;
%mend;

%run_all&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jun 2019 18:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570117#M160734</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-06-30T18:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: SAS crashes, using a macro in a data step because of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570119#M160736</link>
      <description>&lt;P&gt;Whst is the observation size of dataset mem.taq? Given that you multiply the obs count by more than 20000, this will be a crucial number.&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jun 2019 20:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570119#M160736</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-30T20:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS crashes, using a macro in a data step because of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570201#M160774</link>
      <description>&lt;P&gt;Seems like a lot of effort when you can just use %NRSTR() to prevent SAS from generating too many lines of code.&lt;/P&gt;
&lt;P&gt;Because the macro doesn't use parameters you need also protect the setting of the macro variables so that they execute in the right order also.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats('%nrstr(%let) taq_day=',ric_date,';'));
call execute(cats('%nrstr(%let) Mkt_day=',AXJO_date,';'));
call execute('%nrstr(%HFEQ_ALL);');
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or just write the code to a file instead of using CALL EXECUTE.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 12:34:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570201#M160774</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-01T12:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS crashes, using a macro in a data step because of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570222#M160780</link>
      <description>&lt;P&gt;Tom,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I like this version a lot.&amp;nbsp; Do you want to explain to the rest of the board what the issues are, why this is necessary, and show the entire (slightly longer) program?&amp;nbsp; If not, I can do it later today.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 13:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570222#M160780</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-07-01T13:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS crashes, using a macro in a data step because of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570257#M160784</link>
      <description>&lt;P&gt;So here is a little demo of the timing issues around CALL EXECUTE and CALL SYMPUTX().&lt;/P&gt;
&lt;P&gt;First let's define a little macro that references some macro variable that is NOT one of its parameters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mymac;
data _null_;
* Here is the code the macro generates ;
  mvarvalue=symget('mymvar');
  put mvarvalue=;
run;
%mend mymac;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's try a little data step that sets values to the macro variable using CALL SYMPUTX() and calls the macro using CALL EXECUTE().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symput('mymvar','First Value');
  call execute('%mymac;');
  call symput('mymvar','Second Value');
  call execute('%mymac;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice how the code that the macro generates is echoed to the log with the + sign in front of it. Also notice how both runs of the macro used the second value of MYMVAR.&lt;/P&gt;
&lt;PRE&gt;9     data _null_;
10      call symput('mymvar','First Value');
11      call execute('%mymac;');
12      call symput('mymvar','Second Value');
13      call execute('%mymac;');
14    run;

NOTE: DATA statement used (Total process time):
      real time           0.25 seconds
      cpu time            0.01 seconds


NOTE: CALL EXECUTE generated line.
1    + data _null_; * Here is the code the macro generates ;   mvarvalue=symget('mymvar');   put
mvarvalue=; run;

mvarvalue=Second Value
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


1    +
;
2    + data _null_; * Here is the code the macro generates ;   mvarvalue=symget('mymvar');   put
mvarvalue=; run;

mvarvalue=Second Value
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


2    +
;

15
&lt;/PRE&gt;
&lt;P&gt;Now if we use %NRSTR() to prevent the macro call from being expanded while the code it being pushed onto the stack to run.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symput('mymvar','First Value');
  call execute('%nrstr(%mymac);');
  call symput('mymvar','Second Value');
  call execute('%nrstr(%mymac);');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice how now the lines with + in front just show the call to the macro.&amp;nbsp; But the result is still just showing the second value assigned to MYMVAR.&lt;/P&gt;
&lt;PRE&gt;16    data _null_;
17      call symput('mymvar','First Value');
18      call execute('%nrstr(%mymac);');
19      call symput('mymvar','Second Value');
20      call execute('%nrstr(%mymac);');
21    run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


NOTE: CALL EXECUTE generated line.
1    + %mymac;

mvarvalue=Second Value
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


2    + %mymac;

mvarvalue=Second Value
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds



&lt;/PRE&gt;
&lt;P&gt;Now if we use %NRSTR() around %LET to generate a %LET statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call execute(cats('%nrstr(%let) mymvar=','First Value',';'));
  call execute('%nrstr(%mymac);');
  call execute(cats('%nrstr(%let) mymvar=','Second Value',';'));
  call execute('%nrstr(%mymac);');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;We see that the macro variable MYMVAR is updated AFTER the first run of the macro.&lt;/P&gt;
&lt;PRE&gt;22    data _null_;
23      call execute(cats('%nrstr(%let) mymvar=','First Value',';'));
24      call execute('%nrstr(%mymac);');
25      call execute(cats('%nrstr(%let) mymvar=','Second Value',';'));
26      call execute('%nrstr(%mymac);');
27    run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


NOTE: CALL EXECUTE generated line.
1    + %let mymvar=First Value;
2    + %mymac;

mvarvalue=First Value
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


3    + %let mymvar=Second Value;
4    + %mymac;

mvarvalue=Second Value
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds&lt;/PRE&gt;
&lt;P&gt;Finally we can just skip CALL EXECUTE() and use PUT to write the code and %INCLUDE to run it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  file code;
  put '%let mymvar=First Value;';
  put '%mymac;';
  put '%let mymvar=Second Value;';
  put '%mymac;';
run;
%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now we have the full power of the PUT statement to make generating the code easier.&amp;nbsp; We can stop after the data step and examine the generated code and make sure our code generation logic is correct.&amp;nbsp; We can generate code that is formatted the way we like so that the log is easier to read. etc. etc.&lt;/P&gt;
&lt;PRE&gt;37    filename code temp;
38    data _null_;
39      file code;
40      put '%let mymvar=First Value;';
41      put '%mymac;';
42      put '%let mymvar=Second Value;';
43      put '%mymac;';
44    run;

NOTE: The file CODE is:

      Filename=C:\Users\ABERNA~1\AppData\Local\Temp\1\SAS Temporary
      Files\_TD20432_AMRL20L6F1E4992_\#LN00058,
      RECFM=V,LRECL=32767,File Size (bytes)=0,
      Last Modified=01Jul2019:09:52:45,
      Create Time=01Jul2019:09:52:45

NOTE: 4 records were written to the file CODE.
      The minimum record length was 7.
      The maximum record length was 25.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


45    %include code / source2;
NOTE: %INCLUDE (level 1) file CODE is file C:\Users\ABERNA~1\AppData\Local\Temp\1\SAS Temporary
      Files\_TD20432_AMRL20L6F1E4992_\#LN00058.
46   +%let mymvar=First Value;
47   +%mymac;

mvarvalue=First Value
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


48   +%let mymvar=Second Value;
49   +%mymac;

mvarvalue=Second Value
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


NOTE: %INCLUDE (level 1) ending.
&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;PS&lt;/STRONG&gt; If you define your macro to take its inputs as parameters instead of referencing "magic" macro variables that are assumed to have been created in advance then one aspect of the timing problem is eliminated.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call execute('%nrstr(%mymac)(mymvar=First Value)');
  call execute('%nrstr(%mymac)(mymvar=Second Value)');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Jul 2019 14:17:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570257#M160784</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-01T14:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: SAS crashes, using a macro in a data step because of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570577#M160912</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	Data RDWork.TAQ1; 
		pnt=&amp;amp;pt;
		set RDWork.TAQ  point=pnt ;

	if month(date)=12 then stop;

	run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am trying to do a change in code using the POINT that you used. But the data step doesn't stop and goes to end.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 14:19:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570577#M160912</guid>
      <dc:creator>Afshin</dc:creator>
      <dc:date>2019-07-02T14:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: SAS crashes, using a macro in a data step because of memory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570593#M160920</link>
      <description>&lt;P&gt;Try posting the full question as a new question, instead of adding on to an existing question.&amp;nbsp; Most posters will just skip over questions that have already been answered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's probably something simple, but without the details (where does &amp;amp;PT come from, what is in DATE, what is the program supposed to do), it's impossible to answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 15:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-crashes-using-a-macro-in-a-data-step-because-of-memory/m-p/570593#M160920</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-07-02T15:11:17Z</dc:date>
    </item>
  </channel>
</rss>

