<?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: Macro do loop not iterating in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-not-iterating/m-p/589221#M14876</link>
    <description>&lt;P&gt;Macro language does not process the data in your data set.&amp;nbsp; It is not capable of doing that.&amp;nbsp; Whatever you did before either won't be helpful here, or it didn't use macro language.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is likely an application for arrays.&amp;nbsp; To get some help, you will need to type out in full the logic you want to apply to one group of variables, say Med1_1 - Med1_5.&amp;nbsp; If you do that, lots of people will be able to help with the solution.&lt;/P&gt;</description>
    <pubDate>Mon, 16 Sep 2019 23:52:46 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-09-16T23:52:46Z</dc:date>
    <item>
      <title>Macro do loop not iterating</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-not-iterating/m-p/589217#M14875</link>
      <description>&lt;P&gt;I have the following data structure&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Med1_1-Med1_5 Med_oth1&amp;nbsp;&amp;nbsp;Med2_1-Med2_5 Med_oth2&amp;nbsp;Med3_1-Med3_5 Med_oth3 ....&amp;nbsp; &amp;nbsp;Med20_1-Med20_5 Med_oth20&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to do the same thing to the&amp;nbsp; variable in each group of 6 variables "MedX_1-MedX_5 Med_othX" .&amp;nbsp; Basically find the one that is not null and assign that to a new variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have done this before and I cannot find my example. The following is my attempt to do this with a macro and it is not working. Any help would be much appreciated&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro Choose_med;&lt;/P&gt;&lt;P&gt;%do i = 1 %to 20;&lt;/P&gt;&lt;P&gt;%if Med&amp;amp;i._1 = 1 %then Med&amp;amp;i = Med_Ot&amp;amp;i ;&lt;BR /&gt;%else %if Med&amp;amp;i._1 ^= 1 or Med&amp;amp;i._1=. %then %do j = 1 %to 5;&lt;BR /&gt;&lt;BR /&gt;%if Med&amp;amp;i._&amp;amp;j ^= 1 and Med&amp;amp;i._1^=. and Med&amp;amp;i="" %then Med&amp;amp;i = Med&amp;amp;i._j ;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%mend Choose_med;&lt;/P&gt;&lt;P&gt;Data Meds2;&lt;BR /&gt;set meds;&lt;BR /&gt;format Med1-med20 $100.;&lt;BR /&gt;%Choose_med;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2019 23:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-not-iterating/m-p/589217#M14875</guid>
      <dc:creator>Stat_prevmed</dc:creator>
      <dc:date>2019-09-16T23:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro do loop not iterating</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-not-iterating/m-p/589221#M14876</link>
      <description>&lt;P&gt;Macro language does not process the data in your data set.&amp;nbsp; It is not capable of doing that.&amp;nbsp; Whatever you did before either won't be helpful here, or it didn't use macro language.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is likely an application for arrays.&amp;nbsp; To get some help, you will need to type out in full the logic you want to apply to one group of variables, say Med1_1 - Med1_5.&amp;nbsp; If you do that, lots of people will be able to help with the solution.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2019 23:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-not-iterating/m-p/589221#M14876</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-09-16T23:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: Macro do loop not iterating</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-not-iterating/m-p/589326#M14890</link>
      <description>&lt;P&gt;Run the code again, using this command as the first command of your code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then examine the log to see what the problem is. If that doesn't clear things up, show us the log by pasting it into the window that appears when you click on the {i} icon.&amp;nbsp;&lt;STRONG&gt;DO NOT SKIP THIS STEP.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you say: "&lt;SPAN&gt;it is not working". This is never enough information for us. Please describe in words and in detail (and show us if possible) the actual information that leads you to say it is not working.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2019 12:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-not-iterating/m-p/589326#M14890</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-09-17T12:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: Macro do loop not iterating</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-not-iterating/m-p/589346#M14891</link>
      <description>&lt;P&gt;Your approach is confusing macro logic and SAS code logic.&amp;nbsp; For example the condition in the your first %IF can never be true for any value of &amp;amp;I since the letter M is never going to match the digit 1.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Med&amp;amp;i._1 = 1 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want more help so a simple example of what variables you have and what new variables you want to create based on the values of those variables.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2019 13:22:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-do-loop-not-iterating/m-p/589346#M14891</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-17T13:22:33Z</dc:date>
    </item>
  </channel>
</rss>

