<?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: problem with looping through macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70722#M15304</link>
    <description>Art:&lt;BR /&gt;
  I understand what you're saying, but I think the developers were true to the fundamental nature of the macro facility when they built in that behavior. A SAS macro program can generate entire multi-step progarms, single step programs, parts of steps, entire statements, parts of statements or a single character. Whether or not you put a semi-colon in your macro program, especially when you are generating &lt;B&gt;&lt;U&gt;parts of statements&lt;/U&gt;&lt;/B&gt;&lt;U&gt;&lt;/U&gt; really, really depends on what you are trying to have be resolved into code.&lt;BR /&gt;
 &lt;BR /&gt;
  The SAS Macro facility doesn't technically "execute" anything and when a macro program is invoked, it doesn't technically "execute" it only resolves macro triggers and macro variable references and after it is done with all the resolving and building of code, the built code goes forward to the compiler. &lt;BR /&gt;
 &lt;BR /&gt;
  That's why I call the SAS Macro facility a "big typewriter" -- all it's doing is typing code for me. Which is why I ALWAYS recommend that you start with a working SAS program. If I had been writing your macro, I would have started with a working program like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
DATA TEST; &lt;BR /&gt;
M1=200901; &lt;BR /&gt;
M2=200705; &lt;BR /&gt;
                       &lt;BR /&gt;
DIFF=(SUBSTR(PUT(m1,Z6.),1,4)*12 + SUBSTR(PUT(m1,Z6.),5,2)*1) - &lt;BR /&gt;
     (SUBSTR(PUT(m2,Z6.),1,4)*12 + SUBSTR(PUT(m2,Z6.),5,2)*1 )  ; &lt;BR /&gt;
           &lt;BR /&gt;
RUN;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
   &lt;BR /&gt;
The semi-colon at the end of the assignment statement is the ONLY semi-colon that's needed. So, if I am writing a macro program to "type" this for me (shown once for M1):&lt;BR /&gt;
[pre]&lt;BR /&gt;
(SUBSTR(PUT(m1,Z6.),1,4)*12 + SUBSTR(PUT(m1,Z6.),5,2)*1) &lt;BR /&gt;
[/pre]&lt;BR /&gt;
  &lt;BR /&gt;
...then it would be inappropriate to even  put a semi-colon inside the macro program definition. If you turn on the debugging options MPRINT SYMBOLGEN and MLOGIC, you can see in the SAS log, that all the macro facility is doing is typing parts of statements to go forward to the compiler:&lt;BR /&gt;
[pre]&lt;BR /&gt;
978  DATA TEST;&lt;BR /&gt;
979  M1=200901; M2=200705;&lt;BR /&gt;
980  DIFF=%FUNC(M1)-%FUNC(M2);&lt;BR /&gt;
MLOGIC(FUNC):  Beginning execution.&lt;BR /&gt;
MLOGIC(FUNC):  Parameter MONTH has value M1&lt;BR /&gt;
SYMBOLGEN:  Macro variable MONTH resolves to M1&lt;BR /&gt;
SYMBOLGEN:  Macro variable MONTH resolves to M1&lt;BR /&gt;
MPRINT(FUNC):  SUBSTR(PUT(M1,Z6.),1,4)*12 + SUBSTR(PUT(M1,Z6.),5,2)*1   &lt;B&gt;&amp;lt; -- here&lt;/B&gt;&lt;BR /&gt;
MLOGIC(FUNC):  Ending execution.&lt;BR /&gt;
MLOGIC(FUNC):  Beginning execution.&lt;BR /&gt;
MLOGIC(FUNC):  Parameter MONTH has value M2&lt;BR /&gt;
SYMBOLGEN:  Macro variable MONTH resolves to M2&lt;BR /&gt;
SYMBOLGEN:  Macro variable MONTH resolves to M2&lt;BR /&gt;
MPRINT(FUNC):  SUBSTR(PUT(M2,Z6.),1,4)*12 + SUBSTR(PUT(M2,Z6.),5,2)*1  &lt;B&gt;&amp;lt; -- and here&lt;/B&gt;&lt;BR /&gt;
MLOGIC(FUNC):  Ending execution.&lt;BR /&gt;
981  RUN;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                   &lt;BR /&gt;
And these days, with PROC FCMP, I probably wouldn't do this type of thing in a macro program anyway. Truth be told, if all I wanted was the difference between 2 dates, I would have used the INTCK function.&lt;BR /&gt;
[pre]&lt;BR /&gt;
DATA calcdur; &lt;BR /&gt;
M1=200901; &lt;BR /&gt;
M2=200705; &lt;BR /&gt;
                                     &lt;BR /&gt;
DIFF=(SUBSTR(PUT(m1,Z6.),1,4)*12 + SUBSTR(PUT(m1,Z6.),5,2)*1) - &lt;BR /&gt;
     (SUBSTR(PUT(m2,Z6.),1,4)*12 + SUBSTR(PUT(m2,Z6.),5,2)*1) ; &lt;BR /&gt;
put m1= m2= diff=;&lt;BR /&gt;
                                                           &lt;BR /&gt;
date1 = input(put(m1,6.),yymmn6.);&lt;BR /&gt;
date2 = input(put(m2,6.),yymmn6.);&lt;BR /&gt;
month_diff = intck('month',date2,date1);&lt;BR /&gt;
put date1= date2= month_diff=;&lt;BR /&gt;
RUN; &lt;BR /&gt;
                                            &lt;BR /&gt;
ods listing;&lt;BR /&gt;
proc print data=calcdur;&lt;BR /&gt;
  var m1 date1 m2 date2 diff month_diff;&lt;BR /&gt;
  format date1 date2 yymmn6.;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                            &lt;BR /&gt;
cynthia</description>
    <pubDate>Thu, 09 Sep 2010 02:16:34 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2010-09-09T02:16:34Z</dc:date>
    <item>
      <title>problem with looping through macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70709#M15291</link>
      <description>Hello all,&lt;BR /&gt;
&lt;BR /&gt;
here is my macro code:&lt;BR /&gt;
&lt;BR /&gt;
%macro sc(i,resdata);&lt;BR /&gt;
proc iml;&lt;BR /&gt;
	start delcol(x,i);&lt;BR /&gt;
		return(x[,setdif(1:ncol(x),i)]);&lt;BR /&gt;
	finish;	&lt;BR /&gt;
&lt;BR /&gt;
	use test&amp;amp;i;&lt;BR /&gt;
	read all into x;&lt;BR /&gt;
	x=delcol(x,{1,2}); print x;&lt;BR /&gt;
&lt;BR /&gt;
	use &amp;amp;resdata;&lt;BR /&gt;
	read all var {Resid} into y where(id=(&amp;amp;i+1) &amp;amp; Resid^=.); print y;&lt;BR /&gt;
&lt;BR /&gt;
	sc=x*y; print sc;&lt;BR /&gt;
	create newdata&amp;amp;i from sc;&lt;BR /&gt;
	append from sc;&lt;BR /&gt;
	close newdata&amp;amp;i;&lt;BR /&gt;
quit;&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
I want to loop this macro for different values of i:&lt;BR /&gt;
&lt;BR /&gt;
do i=1 to 38;&lt;BR /&gt;
%sc(i,hala);&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
Essentially the sc macro creates a new data set everytime it runs so I want to run it 38 times but I'm not sure how to code my loop to work on its own.&lt;BR /&gt;
&lt;BR /&gt;
Suggestions?</description>
      <pubDate>Wed, 08 Sep 2010 03:25:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70709#M15291</guid>
      <dc:creator>trekvana</dc:creator>
      <dc:date>2010-09-08T03:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: problem with looping through macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70710#M15292</link>
      <description>You would have an outside macro to control / execute 38 times using a %DO I=1 %TO 38;  %END;   and where you call your %SC macro, you would include the macro variable reference &amp;amp;I to resolve a numeric value with each iteration.&lt;BR /&gt;
&lt;BR /&gt;
Include the command below to get additional SASLOG diagnostics output generated with your macro execution / compilation phase (also you can include additional parameters SYMBOLGEN MLOGIC for debugging purposes):&lt;BR /&gt;
&lt;BR /&gt;
OPTIONS SOURCE SOURCE2 MACROGEN MPRINT;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search arguments, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
macro introduction site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
macro variables introduction site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
macro debugging site:sas.com</description>
      <pubDate>Wed, 08 Sep 2010 03:43:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70710#M15292</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-09-08T03:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: problem with looping through macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70711#M15293</link>
      <description>Scott, is this what you mean?&lt;BR /&gt;
&lt;BR /&gt;
%macro blah;&lt;BR /&gt;
%do i = 1 %to 38;&lt;BR /&gt;
 %sc(i,hala);&lt;BR /&gt;
 %end;&lt;BR /&gt;
 %mend;&lt;BR /&gt;
&lt;BR /&gt;
Also Im not sure how I would create a macro variable reference for &amp;amp;i&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: trekvana

Message was edited by: trekvana</description>
      <pubDate>Wed, 08 Sep 2010 03:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70711#M15293</guid>
      <dc:creator>trekvana</dc:creator>
      <dc:date>2010-09-08T03:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: problem with looping through macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70712#M15294</link>
      <description>No - I mentioned that you need to use the SAS macro variable, &amp;amp;I   -- what you have coded is a literal character "i" which will not resolve the number value you want with each %DO / %END iteration.  &lt;BR /&gt;
&lt;BR /&gt;
That is also why I suggested the diagnostic OPTIONS statement to you to help learn about using macro variables, as well as the DOC references.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 08 Sep 2010 03:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70712#M15294</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-09-08T03:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: problem with looping through macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70713#M15295</link>
      <description>Ah ok!. &lt;BR /&gt;
&lt;BR /&gt;
Thanks Scott</description>
      <pubDate>Wed, 08 Sep 2010 03:55:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70713#M15295</guid>
      <dc:creator>trekvana</dc:creator>
      <dc:date>2010-09-08T03:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: problem with looping through macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70714#M15296</link>
      <description>Dear Scott,&lt;BR /&gt;
&lt;BR /&gt;
So here is my new macro:&lt;BR /&gt;
&lt;BR /&gt;
%macro nprme;&lt;BR /&gt;
%do i = 1 %to 2;&lt;BR /&gt;
 %sc(&amp;amp;i,hala);&lt;BR /&gt;
 %end;&lt;BR /&gt;
OPTIONS SOURCE SOURCE2 MACROGEN MPRINT;&lt;BR /&gt;
 %mend nprme;&lt;BR /&gt;
&lt;BR /&gt;
Now when I run my macro with %nprme I get this log:&lt;BR /&gt;
1645  %macro nprme;&lt;BR /&gt;
1646  %do i = 1 %to 2;&lt;BR /&gt;
1647   %sc(&amp;amp;i,hala);&lt;BR /&gt;
1648   %end;&lt;BR /&gt;
1649  OPTIONS SOURCE SOURCE2 MACROGEN MPRINT;&lt;BR /&gt;
1650   %mend nprme;&lt;BR /&gt;
1651&lt;BR /&gt;
1652  %nprme&lt;BR /&gt;
MPRINT(SC):   proc iml;&lt;BR /&gt;
NOTE: IML Ready&lt;BR /&gt;
MPRINT(SC):   start delcol(x,i);&lt;BR /&gt;
MPRINT(SC):   return(x[,setdif(1:ncol(x),i)]);&lt;BR /&gt;
MPRINT(SC):   finish;&lt;BR /&gt;
NOTE: Module DELCOL defined.&lt;BR /&gt;
MPRINT(SC):   use test1;&lt;BR /&gt;
MPRINT(SC):   read all into x;&lt;BR /&gt;
MPRINT(SC):   x=delcol(x,{1,2});&lt;BR /&gt;
MPRINT(SC):   print x;&lt;BR /&gt;
MPRINT(SC):   use hala;&lt;BR /&gt;
MPRINT(SC):   read all var {Resid} into y where(id=(1+1) &amp;amp; Resid^=.);&lt;BR /&gt;
MPRINT(SC):   print y;&lt;BR /&gt;
MPRINT(SC):   sc=x*y;&lt;BR /&gt;
MPRINT(SC):   print sc;&lt;BR /&gt;
MPRINT(SC):   create newdata1 from sc;&lt;BR /&gt;
MPRINT(SC):   append from sc;&lt;BR /&gt;
MPRINT(SC):   close newdata1;&lt;BR /&gt;
NOTE: The data set WORK.NEWDATA1 has 7 observations and 1 variables.&lt;BR /&gt;
MPRINT(SC):   end;&lt;BR /&gt;
&lt;B&gt;ERROR: END does not occur within DO group at line=3391 col=86.&lt;/B&gt;&lt;BR /&gt;
MPRINT(SC):   quit;&lt;BR /&gt;
NOTE: Exiting IML.&lt;BR /&gt;
NOTE: PROCEDURE IML used (Total process time):&lt;BR /&gt;
      real time           0.17 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
MPRINT(NPRME):  ;&lt;BR /&gt;
MPRINT(SC):   proc iml;&lt;BR /&gt;
NOTE: IML Ready&lt;BR /&gt;
MPRINT(SC):   start delcol(x,i);&lt;BR /&gt;
MPRINT(SC):   return(x[,setdif(1:ncol(x),i)]);&lt;BR /&gt;
MPRINT(SC):   finish;&lt;BR /&gt;
NOTE: Module DELCOL defined.&lt;BR /&gt;
MPRINT(SC):   use test2;&lt;BR /&gt;
MPRINT(SC):   read all into x;&lt;BR /&gt;
MPRINT(SC):   x=delcol(x,{1,2});&lt;BR /&gt;
MPRINT(SC):   print x;&lt;BR /&gt;
MPRINT(SC):   use hala;&lt;BR /&gt;
MPRINT(SC):   read all var {Resid} into y where(id=(2+1) &amp;amp; Resid^=.);&lt;BR /&gt;
MPRINT(SC):   print y;&lt;BR /&gt;
MPRINT(SC):   sc=x*y;&lt;BR /&gt;
MPRINT(SC):   print sc;&lt;BR /&gt;
MPRINT(SC):   create newdata2 from sc;&lt;BR /&gt;
MPRINT(SC):   append from sc;&lt;BR /&gt;
MPRINT(SC):   close newdata2;&lt;BR /&gt;
NOTE: The data set WORK.NEWDATA2 has 8 observations and 1 variables.&lt;BR /&gt;
MPRINT(SC):   end;&lt;BR /&gt;
&lt;B&gt;ERROR: END does not occur within DO group at line=3404 col=86.&lt;/B&gt;&lt;BR /&gt;
MPRINT(SC):   quit;&lt;BR /&gt;
NOTE: Exiting IML.&lt;BR /&gt;
NOTE: PROCEDURE IML used (Total process time):&lt;BR /&gt;
      real time           0.17 seconds&lt;BR /&gt;
      cpu time            0.03 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
MPRINT(NPRME):  ;&lt;BR /&gt;
MPRINT(NPRME):   OPTIONS SOURCE SOURCE2 MACROGEN MPRINT;&lt;BR /&gt;
&lt;BR /&gt;
So it seems like the iterations are working and the data sets are also being created but I am confused about that error message. Any insight?

Ok I see what is happening. The loop is adding the END statement right before the QUIT statement in the SC macro. Is that a problem. Looking at the new data sets everything looks good&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: trekvana</description>
      <pubDate>Wed, 08 Sep 2010 04:07:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70714#M15296</guid>
      <dc:creator>trekvana</dc:creator>
      <dc:date>2010-09-08T04:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: problem with looping through macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70715#M15297</link>
      <description>I don't see your SC macro definition in your pasted log (the most recent reply) -- you need to investigate whether there is or is not an END;  statement defined inside the SC macro before the QUIT statement, in your complete SAS program.  If not coded, then you should either contact SAS Tech Support or post over in the IML forum and provide a reference (hyperlink) back to this post-thread -like this:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=42237" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=42237&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Note:  it's important to share *ALL* of your code in this type of situation.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 08 Sep 2010 13:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70715#M15297</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-09-08T13:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: problem with looping through macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70716#M15298</link>
      <description>Trekvana,&lt;BR /&gt;
&lt;BR /&gt;
Like Scott I don't know what your code actually looks like.  Is %SC calling a macro called SC?  If so, your ending those lines with a semi-colon COULD be the cause of your problem.&lt;BR /&gt;
&lt;BR /&gt;
Art</description>
      <pubDate>Wed, 08 Sep 2010 14:54:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70716#M15298</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2010-09-08T14:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: problem with looping through macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70717#M15299</link>
      <description>Here is my complete situation: I am using proc mixed to get the choleski inverses of all my subject covariance matricies and then using my macro to do some matrix computation with the residual vectors in the OUTPM data set.&lt;BR /&gt;
&lt;BR /&gt;
proc mixed data=weight;&lt;BR /&gt;
class id week;&lt;BR /&gt;
model weight=cweek / outpm=hala vciry;&lt;BR /&gt;
repeated week / type=ar(1) subject=id rci=1 to 38;&lt;BR /&gt;
ods output InvCholR(match_all)=test;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%macro sc(i,resdata);&lt;BR /&gt;
proc iml;&lt;BR /&gt;
	start delcol(x,i);&lt;BR /&gt;
		return(x[,setdif(1:ncol(x),i)]);&lt;BR /&gt;
	finish;	&lt;BR /&gt;
&lt;BR /&gt;
	use test&amp;amp;i;&lt;BR /&gt;
	read all into x;&lt;BR /&gt;
	x=delcol(x,{1,2}); print x;&lt;BR /&gt;
&lt;BR /&gt;
	use &amp;amp;resdata;&lt;BR /&gt;
	read all var {Resid} into y where(id=(&amp;amp;i+1) &amp;amp; Resid^=.); print y;&lt;BR /&gt;
&lt;BR /&gt;
	sc=x*y; print sc;&lt;BR /&gt;
	create newdata&amp;amp;i from sc;&lt;BR /&gt;
	append from sc;&lt;BR /&gt;
	close newdata&amp;amp;i;&lt;BR /&gt;
quit;&lt;BR /&gt;
%mend sc;&lt;BR /&gt;
&lt;BR /&gt;
Then I run the macro through my subjects with:&lt;BR /&gt;
&lt;BR /&gt;
%macro nprme;&lt;BR /&gt;
%do i = 1 %to 37;&lt;BR /&gt;
%sc(&amp;amp;i,hala);&lt;BR /&gt;
%end;&lt;BR /&gt;
OPTIONS SOURCE SOURCE2 MACROGEN MPRINT;&lt;BR /&gt;
%mend nprme;&lt;BR /&gt;
&lt;BR /&gt;
%nprme</description>
      <pubDate>Wed, 08 Sep 2010 17:46:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70717#M15299</guid>
      <dc:creator>trekvana</dc:creator>
      <dc:date>2010-09-08T17:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: problem with looping through macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70718#M15300</link>
      <description>Dear Art, &lt;BR /&gt;
&lt;BR /&gt;
you were correct. Once I removed the semi colon from the %sc(&amp;amp;i,resdata):&lt;BR /&gt;
&lt;BR /&gt;
%macro nprme;&lt;BR /&gt;
%do i = 1 %to 37;&lt;BR /&gt;
%sc(&amp;amp;i,hala)&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend nprme;&lt;BR /&gt;
&lt;BR /&gt;
the error code was resolved. I guess I got confused because I thought all statements within a DO loop had to be ended with semi-colons.</description>
      <pubDate>Wed, 08 Sep 2010 18:10:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70718#M15300</guid>
      <dc:creator>trekvana</dc:creator>
      <dc:date>2010-09-08T18:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: problem with looping through macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70719#M15301</link>
      <description>Statements do end with semi-colons.  Macro calls do not.  effectively the semi-colon that followed the macro call was inserted after the QUIT;.  The QUIT became:&lt;BR /&gt;
[pre]&lt;BR /&gt;
quit;;[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Generally a semi-colon by itself (or inthis case a double semi-colon) is not  a problem.  I do not use IML much and am unsure why it would be a problem here.&lt;BR /&gt;
&lt;BR /&gt;
a different Art</description>
      <pubDate>Wed, 08 Sep 2010 18:27:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70719#M15301</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-09-08T18:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: problem with looping through macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70720#M15302</link>
      <description>Hi:&lt;BR /&gt;
  ArtC is correct that macro calls &lt;B&gt;&lt;U&gt;generally&lt;/U&gt;&lt;/B&gt; do not end with a semi-colon. However, in some instances when using SAS/IntrNet or a stored process as part of the SAS Platform for Business Analytics, there are some macro calls that DO end with a semi-colon. I just wanted to get that out in the forum before a gazillion stored process programmers started taking the semi-colon off of %STPBEGIN; calls.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 08 Sep 2010 22:04:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70720#M15302</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-09-08T22:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: problem with looping through macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70721#M15303</link>
      <description>Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
I hope your post negates the gazillion or so programmers doing what they shouldn't do, but my original suggestion was based on an old SAS-L post I recalled where the opposite result was obtained.&lt;BR /&gt;
&lt;BR /&gt;
My point:  it sure helps to know, as part of one's learning, how semicolons can affect macros.&lt;BR /&gt;
&lt;BR /&gt;
For example, try the following two runs (where the presence or absence of the semicolon is INSIDE the macro:)&lt;BR /&gt;
&lt;BR /&gt;
%MACRO FUNC(MONTH); &lt;BR /&gt;
  SUBSTR(PUT(&amp;amp;MONTH,Z6.),1,4)*12 + &lt;BR /&gt;
   SUBSTR(PUT(&amp;amp;MONTH,Z6.),5,2)*1;&lt;BR /&gt;
%MEND; &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
DATA TEST; &lt;BR /&gt;
  M1=200901; M2=200705; &lt;BR /&gt;
  DIFF=%FUNC(M1)-%FUNC(M2); &lt;BR /&gt;
RUN; &lt;BR /&gt;
&lt;BR /&gt;
which will, of course, result in an error, while the following one will run without any problem (other than, of course, the notes about converting text to numbers):&lt;BR /&gt;
&lt;BR /&gt;
%MACRO FUNC(MONTH); &lt;BR /&gt;
  SUBSTR(PUT(&amp;amp;MONTH,Z6.),1,4)*12 + &lt;BR /&gt;
   SUBSTR(PUT(&amp;amp;MONTH,Z6.),5,2)*1&lt;BR /&gt;
%MEND; &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
DATA TEST; &lt;BR /&gt;
  M1=200901; M2=200705; &lt;BR /&gt;
  DIFF=%FUNC(M1)-%FUNC(M2); &lt;BR /&gt;
RUN; &lt;BR /&gt;
&lt;BR /&gt;
I don't want to be too critical, but it would have been nice if the developers of built-in SAS macros had followed the same protocol that has been ingrained into the rest of us.&lt;BR /&gt;
&lt;BR /&gt;
Art</description>
      <pubDate>Wed, 08 Sep 2010 22:57:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70721#M15303</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2010-09-08T22:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: problem with looping through macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70722#M15304</link>
      <description>Art:&lt;BR /&gt;
  I understand what you're saying, but I think the developers were true to the fundamental nature of the macro facility when they built in that behavior. A SAS macro program can generate entire multi-step progarms, single step programs, parts of steps, entire statements, parts of statements or a single character. Whether or not you put a semi-colon in your macro program, especially when you are generating &lt;B&gt;&lt;U&gt;parts of statements&lt;/U&gt;&lt;/B&gt;&lt;U&gt;&lt;/U&gt; really, really depends on what you are trying to have be resolved into code.&lt;BR /&gt;
 &lt;BR /&gt;
  The SAS Macro facility doesn't technically "execute" anything and when a macro program is invoked, it doesn't technically "execute" it only resolves macro triggers and macro variable references and after it is done with all the resolving and building of code, the built code goes forward to the compiler. &lt;BR /&gt;
 &lt;BR /&gt;
  That's why I call the SAS Macro facility a "big typewriter" -- all it's doing is typing code for me. Which is why I ALWAYS recommend that you start with a working SAS program. If I had been writing your macro, I would have started with a working program like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
DATA TEST; &lt;BR /&gt;
M1=200901; &lt;BR /&gt;
M2=200705; &lt;BR /&gt;
                       &lt;BR /&gt;
DIFF=(SUBSTR(PUT(m1,Z6.),1,4)*12 + SUBSTR(PUT(m1,Z6.),5,2)*1) - &lt;BR /&gt;
     (SUBSTR(PUT(m2,Z6.),1,4)*12 + SUBSTR(PUT(m2,Z6.),5,2)*1 )  ; &lt;BR /&gt;
           &lt;BR /&gt;
RUN;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
   &lt;BR /&gt;
The semi-colon at the end of the assignment statement is the ONLY semi-colon that's needed. So, if I am writing a macro program to "type" this for me (shown once for M1):&lt;BR /&gt;
[pre]&lt;BR /&gt;
(SUBSTR(PUT(m1,Z6.),1,4)*12 + SUBSTR(PUT(m1,Z6.),5,2)*1) &lt;BR /&gt;
[/pre]&lt;BR /&gt;
  &lt;BR /&gt;
...then it would be inappropriate to even  put a semi-colon inside the macro program definition. If you turn on the debugging options MPRINT SYMBOLGEN and MLOGIC, you can see in the SAS log, that all the macro facility is doing is typing parts of statements to go forward to the compiler:&lt;BR /&gt;
[pre]&lt;BR /&gt;
978  DATA TEST;&lt;BR /&gt;
979  M1=200901; M2=200705;&lt;BR /&gt;
980  DIFF=%FUNC(M1)-%FUNC(M2);&lt;BR /&gt;
MLOGIC(FUNC):  Beginning execution.&lt;BR /&gt;
MLOGIC(FUNC):  Parameter MONTH has value M1&lt;BR /&gt;
SYMBOLGEN:  Macro variable MONTH resolves to M1&lt;BR /&gt;
SYMBOLGEN:  Macro variable MONTH resolves to M1&lt;BR /&gt;
MPRINT(FUNC):  SUBSTR(PUT(M1,Z6.),1,4)*12 + SUBSTR(PUT(M1,Z6.),5,2)*1   &lt;B&gt;&amp;lt; -- here&lt;/B&gt;&lt;BR /&gt;
MLOGIC(FUNC):  Ending execution.&lt;BR /&gt;
MLOGIC(FUNC):  Beginning execution.&lt;BR /&gt;
MLOGIC(FUNC):  Parameter MONTH has value M2&lt;BR /&gt;
SYMBOLGEN:  Macro variable MONTH resolves to M2&lt;BR /&gt;
SYMBOLGEN:  Macro variable MONTH resolves to M2&lt;BR /&gt;
MPRINT(FUNC):  SUBSTR(PUT(M2,Z6.),1,4)*12 + SUBSTR(PUT(M2,Z6.),5,2)*1  &lt;B&gt;&amp;lt; -- and here&lt;/B&gt;&lt;BR /&gt;
MLOGIC(FUNC):  Ending execution.&lt;BR /&gt;
981  RUN;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                   &lt;BR /&gt;
And these days, with PROC FCMP, I probably wouldn't do this type of thing in a macro program anyway. Truth be told, if all I wanted was the difference between 2 dates, I would have used the INTCK function.&lt;BR /&gt;
[pre]&lt;BR /&gt;
DATA calcdur; &lt;BR /&gt;
M1=200901; &lt;BR /&gt;
M2=200705; &lt;BR /&gt;
                                     &lt;BR /&gt;
DIFF=(SUBSTR(PUT(m1,Z6.),1,4)*12 + SUBSTR(PUT(m1,Z6.),5,2)*1) - &lt;BR /&gt;
     (SUBSTR(PUT(m2,Z6.),1,4)*12 + SUBSTR(PUT(m2,Z6.),5,2)*1) ; &lt;BR /&gt;
put m1= m2= diff=;&lt;BR /&gt;
                                                           &lt;BR /&gt;
date1 = input(put(m1,6.),yymmn6.);&lt;BR /&gt;
date2 = input(put(m2,6.),yymmn6.);&lt;BR /&gt;
month_diff = intck('month',date2,date1);&lt;BR /&gt;
put date1= date2= month_diff=;&lt;BR /&gt;
RUN; &lt;BR /&gt;
                                            &lt;BR /&gt;
ods listing;&lt;BR /&gt;
proc print data=calcdur;&lt;BR /&gt;
  var m1 date1 m2 date2 diff month_diff;&lt;BR /&gt;
  format date1 date2 yymmn6.;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                            &lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 09 Sep 2010 02:16:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70722#M15304</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-09-09T02:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: problem with looping through macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70723#M15305</link>
      <description>Hi, Cynthia:&lt;BR /&gt;
&lt;BR /&gt;
You are making many good points but most are irrelevant to the one Art is making. Only the relevant point seems to be:&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; Whether or not you put a semi-colon in your macro program, especially when you are &lt;BR /&gt;
&amp;gt; generating &lt;B&gt;&lt;U&gt;parts of statements&lt;/U&gt;&lt;/B&gt;&lt;U&gt;&lt;/U&gt; really, really depends on what you are trying to &lt;BR /&gt;
&amp;gt; have be resolved into code.&lt;BR /&gt;
&lt;BR /&gt;
And I don't think you are right. &lt;BR /&gt;
&lt;BR /&gt;
If you are not generating a complete statement in your macro, then you should not include a semi-colon in the macro. If you *are* generating a complete statement in your macro, you *should* include a semi-colon, as well. Otherwise, it simply does not make sense at all.</description>
      <pubDate>Fri, 10 Sep 2010 22:57:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70723#M15305</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2010-09-10T22:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: problem with looping through macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70724#M15306</link>
      <description>Hi:&lt;BR /&gt;
  I do agree with you that &lt;B&gt;almost&lt;/B&gt; 100% of the time you should not use a semi-colon when your macro is generating parts of statements. However, I have generated form letters with macro coding, in which the syntax of various text variables that were being built, from concatenated macro variables and text strings and macro calls, did require the use of a semi-colon as punctuation -- for the paragraph to be correct. Those semi-colons then needed to be masked or protected with macro quoting functions so they were treated as part of the text paragraph.&lt;BR /&gt;
&lt;BR /&gt;
  This did not seem an appropriate posting to go into the finer points of when you might need a macro quoting function to protect a semi-colon, a single quote or a percent sign. So I waffled with the "really, really depends". &lt;BR /&gt;
&lt;BR /&gt;
  It seems to me, now,  that what I should have said was that if you ALWAYS start with a working SAS program and then figure out what code you need to generate when your macro program executes, you will ALWAYS know, with 100% certainty,  whether or not a semi-colon, as needed by SAS, is appropriate.&lt;BR /&gt;
 &lt;BR /&gt;
  Thank you for pointing out the imprecision of my language.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Sat, 11 Sep 2010 02:56:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-looping-through-macros/m-p/70724#M15306</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-09-11T02:56:13Z</dc:date>
    </item>
  </channel>
</rss>

