<?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 Macro DO loop not looping through full character list in SAS Studio in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Macro-DO-loop-not-looping-through-full-character-list-in-SAS/m-p/506662#M1369</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Really stumped by this one (so probably something really obvious that I'm missing).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to develop a macro with nested DO loops to cycle through all possible combinations of two sets of character variables and 3 sets of numeric variables. The full code is quite lengthy but I'm hoping what I show here will contain the relevant parts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To cycle through my list of character variables I have coded the following (the first variable has two categories, the second has four): -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let h_lst = HA NH;&lt;BR /&gt;%let start=%sysfunc(indexc(%sysfunc(compress(&amp;amp;h_lst)),&amp;amp;beg));&lt;BR /&gt;%let finish=%sysfunc(indexc(%sysfunc(compress(&amp;amp;h_lst)),&amp;amp;end));&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;%let g_lst = AW CHASE FLAT HURDLE;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;%let start1=%sysfunc(indexc(%sysfunc(compress(&amp;amp;g_lst)),&amp;amp;beg1));&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;%let finish1=%sysfunc(indexc(%sysfunc(compress(&amp;amp;g_lst)),&amp;amp;end1));&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;%do h = &amp;amp;start %to &amp;amp;finish;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;%do g = &amp;amp;start1 %to &amp;amp;finish1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;%do i=9 %to 9;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;%do j=9 %to 9;&lt;BR /&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;%do k=28 %to 30;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I call the macro using keyword parameters: -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro super_macro&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;(beg=HA,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; end=NH,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; beg1=AW,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; end1=HURDLE);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the macro, it cycles through all my required variables apart from those in h_lst. The log tells me that although SAS is identifying the list has a BEG of HA and an END of NH, that part of the loop has a start and end value of 1, where I would expect the start value to be 1 and the end value to be 2. The exact same code method used for g_lst works fine and has a start value of 1 and end value of 4. The log for this section is below: -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasSource"&gt;MLOGIC(SUPER_MACRO): %LET (variable name is H_LST)&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(SUPER_MACRO): %LET (variable name is START)&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable H_LST resolves to HA NH&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable BEG resolves to HA&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(SUPER_MACRO): %LET (variable name is FINISH)&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable H_LST resolves to HA NH&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable END resolves to NH&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(SUPER_MACRO): %LET (variable name is G_LST)&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(SUPER_MACRO): %LET (variable name is START1)&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable G_LST resolves to AW CHASE FLAT HURDLE&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable BEG1 resolves to AW&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(SUPER_MACRO): %LET (variable name is FINISH1)&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable G_LST resolves to AW CHASE FLAT HURDLE&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable END1 resolves to HURDLE&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable START resolves to 1&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable FINISH resolves to 1&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(SUPER_MACRO): %DO loop beginning; index variable H; start value is 1; stop value is 1; by value is 1.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable START1 resolves to 1&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable FINISH1 resolves to 4&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(SUPER_MACRO): %DO loop beginning; index variable G; start value is 1; stop value is 4; by value is 1.&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I say, it's probably something really obvious that I'm missing but I just can't figure it out so if anyone could point me in the right direction, I'd be hugely appreciative.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Oct 2018 20:53:41 GMT</pubDate>
    <dc:creator>robulon</dc:creator>
    <dc:date>2018-10-22T20:53:41Z</dc:date>
    <item>
      <title>Macro DO loop not looping through full character list in SAS Studio</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-DO-loop-not-looping-through-full-character-list-in-SAS/m-p/506662#M1369</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Really stumped by this one (so probably something really obvious that I'm missing).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to develop a macro with nested DO loops to cycle through all possible combinations of two sets of character variables and 3 sets of numeric variables. The full code is quite lengthy but I'm hoping what I show here will contain the relevant parts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To cycle through my list of character variables I have coded the following (the first variable has two categories, the second has four): -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let h_lst = HA NH;&lt;BR /&gt;%let start=%sysfunc(indexc(%sysfunc(compress(&amp;amp;h_lst)),&amp;amp;beg));&lt;BR /&gt;%let finish=%sysfunc(indexc(%sysfunc(compress(&amp;amp;h_lst)),&amp;amp;end));&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;%let g_lst = AW CHASE FLAT HURDLE;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;%let start1=%sysfunc(indexc(%sysfunc(compress(&amp;amp;g_lst)),&amp;amp;beg1));&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;%let finish1=%sysfunc(indexc(%sysfunc(compress(&amp;amp;g_lst)),&amp;amp;end1));&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;%do h = &amp;amp;start %to &amp;amp;finish;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;%do g = &amp;amp;start1 %to &amp;amp;finish1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;%do i=9 %to 9;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;%do j=9 %to 9;&lt;BR /&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;%do k=28 %to 30;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I call the macro using keyword parameters: -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro super_macro&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;(beg=HA,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; end=NH,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; beg1=AW,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; end1=HURDLE);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the macro, it cycles through all my required variables apart from those in h_lst. The log tells me that although SAS is identifying the list has a BEG of HA and an END of NH, that part of the loop has a start and end value of 1, where I would expect the start value to be 1 and the end value to be 2. The exact same code method used for g_lst works fine and has a start value of 1 and end value of 4. The log for this section is below: -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasSource"&gt;MLOGIC(SUPER_MACRO): %LET (variable name is H_LST)&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(SUPER_MACRO): %LET (variable name is START)&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable H_LST resolves to HA NH&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable BEG resolves to HA&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(SUPER_MACRO): %LET (variable name is FINISH)&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable H_LST resolves to HA NH&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable END resolves to NH&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(SUPER_MACRO): %LET (variable name is G_LST)&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(SUPER_MACRO): %LET (variable name is START1)&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable G_LST resolves to AW CHASE FLAT HURDLE&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable BEG1 resolves to AW&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(SUPER_MACRO): %LET (variable name is FINISH1)&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable G_LST resolves to AW CHASE FLAT HURDLE&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable END1 resolves to HURDLE&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable START resolves to 1&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable FINISH resolves to 1&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(SUPER_MACRO): %DO loop beginning; index variable H; start value is 1; stop value is 1; by value is 1.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable START1 resolves to 1&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;SYMBOLGEN: Macro variable FINISH1 resolves to 4&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(SUPER_MACRO): %DO loop beginning; index variable G; start value is 1; stop value is 4; by value is 1.&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I say, it's probably something really obvious that I'm missing but I just can't figure it out so if anyone could point me in the right direction, I'd be hugely appreciative.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 20:53:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-DO-loop-not-looping-through-full-character-list-in-SAS/m-p/506662#M1369</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2018-10-22T20:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro DO loop not looping through full character list in SAS Studio</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-DO-loop-not-looping-through-full-character-list-in-SAS/m-p/506680#M1372</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/62592"&gt;@robulon&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are using the wrong function: INDEXC searches for &lt;EM&gt;single characters&lt;/EM&gt; from the list in the second argument. So, it finds the "H"&amp;nbsp;from&amp;nbsp;list "N&lt;STRONG&gt;H&lt;/STRONG&gt;" in the &lt;STRONG&gt;first&lt;/STRONG&gt; position of the string "&lt;STRONG&gt;H&lt;/STRONG&gt;ANH", hence the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider using FIND, INDEX, FINDW, INDEXW or SCAN (for the latter three your application of COMPRESS is counterproductive) or better, since you're working with macro variables, %INDEX or %SCAN. Even FIND, INDEX and %INDEX could be impaired by COMPRESSing (depending on input data), although less than %SCAN.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 21:49:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-DO-loop-not-looping-through-full-character-list-in-SAS/m-p/506680#M1372</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-10-22T21:49:27Z</dc:date>
    </item>
    <item>
      <title>Re: Macro DO loop not looping through full character list in SAS Studio</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-DO-loop-not-looping-through-full-character-list-in-SAS/m-p/506689#M1377</link>
      <description>&lt;P&gt;Of course! That is brilliant, thanks so much for this.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 22:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-DO-loop-not-looping-through-full-character-list-in-SAS/m-p/506689#M1377</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2018-10-22T22:06:08Z</dc:date>
    </item>
  </channel>
</rss>

