<?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: Looping through macro variable in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Looping-through-macro-variable/m-p/74978#M8509</link>
    <description>You are mixing SAS MACRO language processing with DATA step code.  Your DO I=...  statement must change to be a %DO;&lt;YOUR_CODE&gt;; %END;  which will compile SAS DATA step code to be executed.  Also, your DO (s/b %DO) construct is not valid and so you must find a suitable alternative to parse your macro variable using %LET assignment stmt and %SCAN macro function into a sub-field macro variable which you would reference in your code instead of the &amp;amp;I macro variable.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
SAS Macro Language Reference: Intro to Macro Facility&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002293969.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002293969.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
SAS Macro Programming for Beginners&lt;BR /&gt;
Susan J. Slaughter, Avocet Solutions, Davis, CA&lt;BR /&gt;
Lora D. Delwiche, Delwiche Consulting, Winters, CA&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi29/243-29.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi29/243-29.pdf&lt;/A&gt;&lt;/YOUR_CODE&gt;</description>
    <pubDate>Thu, 08 Oct 2009 13:21:33 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-10-08T13:21:33Z</dc:date>
    <item>
      <title>Looping through macro variable</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Looping-through-macro-variable/m-p/74977#M8508</link>
      <description>Hi.&lt;BR /&gt;
I am trying to loop through a macro variable and a field in a datastep, but am struggling with the coding.&lt;BR /&gt;
&lt;BR /&gt;
This code shows what I would like to do:&lt;BR /&gt;
&lt;BR /&gt;
%Let adjust0904 = 1.1;&lt;BR /&gt;
%Let adjust0905 = 1.2;&lt;BR /&gt;
%Let adjust0906 = 1.3;&lt;BR /&gt;
&lt;BR /&gt;
DATA survey;&lt;BR /&gt;
   INPUT id mass0904 mass0905 mass0906 height0904 height0905 height0906;&lt;BR /&gt;
   DATALINES;&lt;BR /&gt;
1  55 56 57 1.7 1.72 1.75&lt;BR /&gt;
2  90 88 90 1.8 1.8 1.8&lt;BR /&gt;
3  55 57 60 1.6 1.6 1.6&lt;BR /&gt;
;&lt;BR /&gt;
PROC PRINT; RUN;&lt;BR /&gt;
&lt;BR /&gt;
Data B;&lt;BR /&gt;
Set A;&lt;BR /&gt;
&lt;BR /&gt;
Do i = '0904', '0905', '0906';&lt;BR /&gt;
If mass&amp;amp;i &amp;gt; 85 Then BMI&amp;amp;i = mass&amp;amp;i * height&amp;amp;i * &amp;amp;adjust&amp;amp;i;&lt;BR /&gt;
* code should read: If mass0904 &amp;gt; 85 Then BMI0904 = mass0904 * height0904 * &amp;amp;adjust0904;&lt;BR /&gt;
End;&lt;BR /&gt;
&lt;BR /&gt;
Run;&lt;BR /&gt;
&lt;BR /&gt;
I realise that there are fundamental flaws with this code (e.g. using "i" as a macro variable), but I hope it shows what I would like to do.  Any suggestions / solutions would be appreciated.&lt;BR /&gt;
Thanks very much&lt;BR /&gt;
Robin</description>
      <pubDate>Thu, 08 Oct 2009 08:13:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Looping-through-macro-variable/m-p/74977#M8508</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-08T08:13:46Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through macro variable</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Looping-through-macro-variable/m-p/74978#M8509</link>
      <description>You are mixing SAS MACRO language processing with DATA step code.  Your DO I=...  statement must change to be a %DO;&lt;YOUR_CODE&gt;; %END;  which will compile SAS DATA step code to be executed.  Also, your DO (s/b %DO) construct is not valid and so you must find a suitable alternative to parse your macro variable using %LET assignment stmt and %SCAN macro function into a sub-field macro variable which you would reference in your code instead of the &amp;amp;I macro variable.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
SAS Macro Language Reference: Intro to Macro Facility&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002293969.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002293969.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
SAS Macro Programming for Beginners&lt;BR /&gt;
Susan J. Slaughter, Avocet Solutions, Davis, CA&lt;BR /&gt;
Lora D. Delwiche, Delwiche Consulting, Winters, CA&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi29/243-29.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi29/243-29.pdf&lt;/A&gt;&lt;/YOUR_CODE&gt;</description>
      <pubDate>Thu, 08 Oct 2009 13:21:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Looping-through-macro-variable/m-p/74978#M8509</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-10-08T13:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through macro variable</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Looping-through-macro-variable/m-p/74979#M8510</link>
      <description>Hi:&lt;BR /&gt;
  In addition to Scott's comments, it occurs to me that you may only need a simple array in order to perform repetitive calculations and not a SAS macro %DO loop at all. Something like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
  array ms mass0904-mass0906;&lt;BR /&gt;
  array ht height0904-height0906;&lt;BR /&gt;
  array bmi bmi0904-bmi0906;&lt;BR /&gt;
  array aj adjust0904-adjust0906;&lt;BR /&gt;
  do i = 1 to 3 by 1;&lt;BR /&gt;
       if ms(i) gt 85 then bmi(i) = ms(i) * ht(i) *aj(i);&lt;BR /&gt;
  end;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Refer to this paper for an example of using a simple array -- Example 1.&lt;BR /&gt;
 &lt;A href="http://support.sas.com/rnd/papers/sgf07/arrays1780.pdf" target="_blank"&gt;http://support.sas.com/rnd/papers/sgf07/arrays1780.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 08 Oct 2009 14:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Looping-through-macro-variable/m-p/74979#M8510</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-10-08T14:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through macro variable</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Looping-through-macro-variable/m-p/74980#M8511</link>
      <description>That is great, thanks!  The only thing is - can you pass the macro variable adjust090x to an array in the datastep?  Have tried a simple "array aj &amp;amp;adjust0904 - &amp;amp;adjust0906;" but SAS does not like this.&lt;BR /&gt;
Cheers&lt;BR /&gt;
Robin</description>
      <pubDate>Thu, 08 Oct 2009 16:02:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Looping-through-macro-variable/m-p/74980#M8511</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-08T16:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through macro variable</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Looping-through-macro-variable/m-p/74981#M8512</link>
      <description>Hi:&lt;BR /&gt;
  I'm not sure I understand what you mean by: &lt;BR /&gt;
&lt;B&gt;pass the macro variable adjust090x to an array in a datastep&lt;/B&gt;&lt;BR /&gt;
 &lt;BR /&gt;
are you saying that you have %let statements, such as:&lt;BR /&gt;
%let adj0904 = 4.5;&lt;BR /&gt;
%let adj0905 = 5.5;&lt;BR /&gt;
%let adj0906 = 6.5;&lt;BR /&gt;
(or some other process that creates these macro variables...)&lt;BR /&gt;
&lt;BR /&gt;
and then you  want to reference those macro values as -though- they were in a data step array. Yes, you can. Look at the set up for a _TEMPORARY_ array in that paper (in Example 2). A temporary array contains a list of "constants", in your case, numeric constants and one way of creating the temporary array would be to hard-code the values. Another way would be to use macro variables.&lt;BR /&gt;
[pre]&lt;BR /&gt;
array aj{3} _temporary_ (4.5, 5.5, 6.5);&lt;BR /&gt;
   &lt;BR /&gt;
could also be defined as:&lt;BR /&gt;
             &lt;BR /&gt;
array aj{3} _temporary_ (&amp;amp;adj0904, &amp;amp;adj0905, &amp;amp;adj0906);&lt;BR /&gt;
(assuming that the 3 macro variables used above all have values before the data step program starts processing.)&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
You could get more complex in the SAS macro program, however, it is better to start simple and get a working program and correct logic, before you go to town with fancy macro processing.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 08 Oct 2009 16:16:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Looping-through-macro-variable/m-p/74981#M8512</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-10-08T16:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through macro variable</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Looping-through-macro-variable/m-p/74982#M8513</link>
      <description>Cynthia, I think you have hit the jackpot!!  It works perfectly on my small example, but will try it on the main program.  Thanks to you guys for your help!&lt;BR /&gt;
Cheers&lt;BR /&gt;
Robin</description>
      <pubDate>Thu, 08 Oct 2009 16:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Looping-through-macro-variable/m-p/74982#M8513</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-08T16:23:36Z</dc:date>
    </item>
  </channel>
</rss>

