<?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: The difference between Macro Loop and a normal loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/The-difference-between-Macro-Loop-and-a-normal-loop/m-p/218605#M40278</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Without seeing input or expected output details may be rough. but the %do/%end controls the creation of code by the SAS Macro processor and Do /end is a data step code construct.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your example macro if invoked as&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%test1b (Orio);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Will generate the following data step code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data advance.test1b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set advance.test1a;&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; where test2='abc';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%test1b (Fred); would generate&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data advance.test1b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set advance.test1a;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;NOTE that the comparison is going to be case sensitive: ORIO is not equal to Orio or oRio.&lt;/P&gt;&lt;P&gt;You might want to add:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let &amp;amp;type=%upcase(&amp;amp;type); before the Data statement and use&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if &amp;amp;type=ORIO %then %do;&lt;/P&gt;&lt;P&gt;to reduce case issues.&lt;/P&gt;&lt;P&gt;if you use&lt;/P&gt;&lt;P&gt;if &amp;amp;type=Orio %then %do;&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; where test2='abc';&lt;/P&gt;&lt;P&gt; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then the data step generated looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data advance.test1b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set advance.test1a;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Orio=Orio then do;&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; where test2='abc';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;Which assumes ORIO is a variable and SAS will create any variable references with missing values.&lt;/P&gt;&lt;P&gt;HINT: Use the SAS macro options to look at what code is created by your macro:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options mprint symbolgen mlogic; will show the lines of code generated in the LOG, the resolution of macro variables as they are used and the results of logic involving macro comparisons.&lt;/P&gt;&lt;P&gt;Use options nomprint nosymbolgen nomlogic; to turn the resolution off. You may use any or all of these as need. I generally start with MPRINT and add symbolgen if some variable looks like it isn't resolving correctly.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 26 May 2015 16:17:48 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2015-05-26T16:17:48Z</dc:date>
    <item>
      <title>The difference between Macro Loop and a normal loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-difference-between-Macro-Loop-and-a-normal-loop/m-p/218604#M40277</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am working on macro facility and when I writes the codes,&lt;/P&gt;&lt;P&gt;sometimes it is difficult for me to determine when to use a macro loop&amp;nbsp; and when not to.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is an example of my code:&lt;/P&gt;&lt;P&gt;%macro test1b(type);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data advance.test1b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set advance.test1a;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if &amp;amp;type=Orio %then %do;&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; where test2='abc';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%mend test1b;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The function of the code is to first check whether user inputs the parameter 'Orio', and if it is true then executes the 'where' clause.&lt;/P&gt;&lt;P&gt;I found that whether or not I add a % in the loop, the outputs are very similar except a variable named "Orio' is created when % is not used.&lt;/P&gt;&lt;P&gt;I do not quite understand the difference in the use of %, and may someone please explain with respect to the above example?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;&lt;P&gt;Casey&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 24 May 2015 10:52:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-difference-between-Macro-Loop-and-a-normal-loop/m-p/218604#M40277</guid>
      <dc:creator>yukclam9</dc:creator>
      <dc:date>2015-05-24T10:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: The difference between Macro Loop and a normal loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-difference-between-Macro-Loop-and-a-normal-loop/m-p/218605#M40278</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Without seeing input or expected output details may be rough. but the %do/%end controls the creation of code by the SAS Macro processor and Do /end is a data step code construct.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your example macro if invoked as&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%test1b (Orio);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Will generate the following data step code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data advance.test1b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set advance.test1a;&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; where test2='abc';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%test1b (Fred); would generate&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data advance.test1b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set advance.test1a;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;NOTE that the comparison is going to be case sensitive: ORIO is not equal to Orio or oRio.&lt;/P&gt;&lt;P&gt;You might want to add:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let &amp;amp;type=%upcase(&amp;amp;type); before the Data statement and use&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if &amp;amp;type=ORIO %then %do;&lt;/P&gt;&lt;P&gt;to reduce case issues.&lt;/P&gt;&lt;P&gt;if you use&lt;/P&gt;&lt;P&gt;if &amp;amp;type=Orio %then %do;&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; where test2='abc';&lt;/P&gt;&lt;P&gt; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then the data step generated looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data advance.test1b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set advance.test1a;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Orio=Orio then do;&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; where test2='abc';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;Which assumes ORIO is a variable and SAS will create any variable references with missing values.&lt;/P&gt;&lt;P&gt;HINT: Use the SAS macro options to look at what code is created by your macro:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options mprint symbolgen mlogic; will show the lines of code generated in the LOG, the resolution of macro variables as they are used and the results of logic involving macro comparisons.&lt;/P&gt;&lt;P&gt;Use options nomprint nosymbolgen nomlogic; to turn the resolution off. You may use any or all of these as need. I generally start with MPRINT and add symbolgen if some variable looks like it isn't resolving correctly.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2015 16:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-difference-between-Macro-Loop-and-a-normal-loop/m-p/218605#M40278</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-05-26T16:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: The difference between Macro Loop and a normal loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-difference-between-Macro-Loop-and-a-normal-loop/m-p/218606#M40279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I put a brief discussion of the difference in this paper: &lt;A href="http://support.sas.com/resources/papers/proceedings13/120-2013.pdf" title="http://support.sas.com/resources/papers/proceedings13/120-2013.pdf"&gt;http://support.sas.com/resources/papers/proceedings13/120-2013.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;cynthia&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 May 2015 00:17:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-difference-between-Macro-Loop-and-a-normal-loop/m-p/218606#M40279</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2015-05-27T00:17:45Z</dc:date>
    </item>
  </channel>
</rss>

