<?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: Wait for macro to finish in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Wait-for-macro-to-finish/m-p/665190#M198850</link>
    <description>&lt;P&gt;Timing.&lt;/P&gt;
&lt;P&gt;When your have something like that calls a macro inside a data step:&lt;/P&gt;
&lt;PRE&gt;	data _NULL_;
		set pg.people(obs=5);
		CALL SYMPUT("person_id",strip(person_id));
		put 'START WORK:' person_id;
		%inner2;
	run;&lt;/PRE&gt;
&lt;P&gt;The macro %inner2 executes when the data _null_ step compiles.&lt;/P&gt;
&lt;P&gt;So you may want:&lt;/P&gt;
&lt;PRE&gt;	data _NULL_;
		set pg.people(obs=5);
		CALL SYMPUT("person_id",strip(person_id));
		put 'START WORK:' person_id;
       run;
      %inner2;
&lt;/PRE&gt;
&lt;P&gt;What do you expect from this? You are reading 5 observations and the value of the macro variable &amp;amp;person_id will be that of the last of the 5 (or any number) read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to do something for each record in your input set PG.People you may be looking for the function CALL EXECUTE to create the code that runs after the data step completes.&lt;/P&gt;</description>
    <pubDate>Thu, 25 Jun 2020 23:04:45 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-06-25T23:04:45Z</dc:date>
    <item>
      <title>Wait for macro to finish</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wait-for-macro-to-finish/m-p/665187#M198849</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let performance_range_start = 2019-11-01;
%let performance_range_end = 2020-02-01;

%macro inner2;

%put 'UPDATE DATA FOR:' &amp;amp;person_id;

%mend;

%macro inner1;
	data _NULL_;
		set pg.people(obs=5);
		CALL SYMPUT("person_id",strip(person_id));
		put 'START WORK:' person_id;
		%inner2;
	run;
%mend;

%macro outer;
   %let start=%sysfunc(inputn(&amp;amp;performance_range_start,yymmdd10.));
   %let end=%sysfunc(inputn(&amp;amp;performance_range_end,yymmdd10.));
   %let dif=%sysfunc(intck(month,&amp;amp;start,&amp;amp;end));
   %do i=0 %to &amp;amp;dif;
   	  %let r_start=%sysfunc(intnx(month,&amp;amp;start,&amp;amp;i,b),date9.);
	  %put 'PROCESS:' &amp;amp;r_start;
      %inner1;
   %end;
%mend;

%outer;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;which outputs:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;START WORK:1
START WORK:2
START WORK:3
START WORK:4
START WORK:5
'PROCESS:' 01DEC2019
'UPDATE DATA FOR:' 5&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;...&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I was expecting:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;START WORK:1
'PROCESS:' 01DEC2019
'UPDATE DATA FOR:' 1
START WORK:2
'PROCESS:' 01DEC2019
'UPDATE DATA FOR:' 2
START WORK:3
'PROCESS:' 01DEC2019
'UPDATE DATA FOR:' 3
START WORK:4
'PROCESS:' 01DEC2019
'UPDATE DATA FOR:' 4

...
...&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any pointers to where I am going wrong here? Do I somehow need to wait for the inner macros to finish before processing the next observation on the outer macro?&lt;BR /&gt;&lt;BR /&gt;Many thanks in advance,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Olli&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 22:38:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wait-for-macro-to-finish/m-p/665187#M198849</guid>
      <dc:creator>ojaro</dc:creator>
      <dc:date>2020-06-25T22:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: Wait for macro to finish</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wait-for-macro-to-finish/m-p/665190#M198850</link>
      <description>&lt;P&gt;Timing.&lt;/P&gt;
&lt;P&gt;When your have something like that calls a macro inside a data step:&lt;/P&gt;
&lt;PRE&gt;	data _NULL_;
		set pg.people(obs=5);
		CALL SYMPUT("person_id",strip(person_id));
		put 'START WORK:' person_id;
		%inner2;
	run;&lt;/PRE&gt;
&lt;P&gt;The macro %inner2 executes when the data _null_ step compiles.&lt;/P&gt;
&lt;P&gt;So you may want:&lt;/P&gt;
&lt;PRE&gt;	data _NULL_;
		set pg.people(obs=5);
		CALL SYMPUT("person_id",strip(person_id));
		put 'START WORK:' person_id;
       run;
      %inner2;
&lt;/PRE&gt;
&lt;P&gt;What do you expect from this? You are reading 5 observations and the value of the macro variable &amp;amp;person_id will be that of the last of the 5 (or any number) read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to do something for each record in your input set PG.People you may be looking for the function CALL EXECUTE to create the code that runs after the data step completes.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 23:04:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wait-for-macro-to-finish/m-p/665190#M198850</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-25T23:04:45Z</dc:date>
    </item>
    <item>
      <title>Re: Wait for macro to finish</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wait-for-macro-to-finish/m-p/665205#M198861</link>
      <description>&lt;P&gt;There is no reason for %inner2 to use any macro language.&amp;nbsp; You could easily change its definition to be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro inner2;

put 'UPDATE DATA FOR:' person_id;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In fact, you might just include the PUT statement in the DATA step itself, without definining %inner2 at all.&amp;nbsp; You created the START WORK logic with no macro language, you could be able to similarly create the UPDATE DATA FOR logic with no macro language.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With a little more of a description of the intention, you might be able to get rid of all the macro language except for the two %LET statements at top.&amp;nbsp; The DATA step "knows" how to manipulate data much more easily than macro language does.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2020 00:30:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wait-for-macro-to-finish/m-p/665205#M198861</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-06-26T00:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: Wait for macro to finish</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wait-for-macro-to-finish/m-p/665272#M198890</link>
      <description>&lt;P&gt;Try this non-macro approach&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start = '01Nov2019'd;
%let end = '01Feb2020'd;

data _null_;
set pg.people (obs=5);
format r_start date9.;
dif=intck('month',&amp;amp;start,&amp;amp;end);
do i=0 to dif;
	put 'START WORK: ' person_id;
	r_start=intnx('month',&amp;amp;start,i,'b');
	put 'PROCESS: ' r_start;
	put 'UPDATE DATA FOR: ' person_id;
	put;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jun 2020 08:09:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wait-for-macro-to-finish/m-p/665272#M198890</guid>
      <dc:creator>sustagens</dc:creator>
      <dc:date>2020-06-26T08:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: Wait for macro to finish</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wait-for-macro-to-finish/m-p/665295#M198898</link>
      <description>Thanks so much for explaining how SAS data step executes. I can confirm that by changing my code to use CALL EXECUTE, I can see the desired effect.&lt;BR /&gt;&lt;BR /&gt;Thanks again,&lt;BR /&gt;&lt;BR /&gt;Olli&lt;BR /&gt;</description>
      <pubDate>Fri, 26 Jun 2020 10:17:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wait-for-macro-to-finish/m-p/665295#M198898</guid>
      <dc:creator>ojaro</dc:creator>
      <dc:date>2020-06-26T10:17:46Z</dc:date>
    </item>
  </channel>
</rss>

