<?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 variables. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables/m-p/37825#M7525</link>
    <description>Sorry, double posting.

Message was edited by: Daniel Santos</description>
    <pubDate>Thu, 28 May 2009 15:13:03 GMT</pubDate>
    <dc:creator>DanielSantos</dc:creator>
    <dc:date>2009-05-28T15:13:03Z</dc:date>
    <item>
      <title>Macro variables.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables/m-p/37824#M7524</link>
      <description>A macro looking something like this will work:&lt;BR /&gt;
&lt;BR /&gt;
%macro firstmacro;&lt;BR /&gt;
%do i=1 %to 10;&lt;BR /&gt;
data newtable&amp;amp;i;&lt;BR /&gt;
set oldtable;&lt;BR /&gt;
do j=1 to 5&lt;BR /&gt;
SOMETHING...;&lt;BR /&gt;
if SOMETHING_ELSE then output newtable&amp;amp;i;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend;&lt;BR /&gt;
%firstmacro;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
But if I would like to do something like this:&lt;BR /&gt;
&lt;BR /&gt;
%macro secondmacro;&lt;BR /&gt;
%do i=1 %to 10;&lt;BR /&gt;
data newtable&amp;amp;i;&lt;BR /&gt;
set oldtable;&lt;BR /&gt;
array var(5);&lt;BR /&gt;
%do j=1 %to 5&lt;BR /&gt;
if x=var(&amp;amp;j) then&lt;BR /&gt;
do;&lt;BR /&gt;
n&amp;amp;j+1;&lt;BR /&gt;
output newtable&amp;amp;i;&lt;BR /&gt;
end;&lt;BR /&gt;
%end;&lt;BR /&gt;
run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend;&lt;BR /&gt;
%secondmacro;&lt;BR /&gt;
&lt;BR /&gt;
In firstmacro I have a do loop with variable j, i.e. not %do.&lt;BR /&gt;
&lt;BR /&gt;
In secondmacro I want to get n1, n2, ..., n5, so I need to code n&amp;amp;j.&lt;BR /&gt;
&lt;BR /&gt;
This could probably be solved much simpler. I am just illustrating the question.&lt;BR /&gt;
&lt;BR /&gt;
When does a variable become a macro variable inside a macro?&lt;BR /&gt;
&lt;BR /&gt;
Does j become a macro variabel in secondmacro because of %do j... and not do j...?&lt;BR /&gt;
&lt;BR /&gt;
Is the code in secondmacro correct?&lt;BR /&gt;
&lt;BR /&gt;
Susan</description>
      <pubDate>Thu, 28 May 2009 11:44:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variables/m-p/37824#M7524</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-28T11:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variables.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables/m-p/37825#M7525</link>
      <description>Sorry, double posting.

Message was edited by: Daniel Santos</description>
      <pubDate>Thu, 28 May 2009 15:13:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variables/m-p/37825#M7525</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-05-28T15:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variables.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variables/m-p/37826#M7526</link>
      <description>Answering question 1.&lt;BR /&gt;
&lt;BR /&gt;
I think you are dealing with the compile-time vs run-time dilema.&lt;BR /&gt;
&lt;BR /&gt;
To create a macro var from within a datastep (run-time), you should use the call symput statement.&lt;BR /&gt;
the %let statement does the same at compile-time.&lt;BR /&gt;
&lt;BR /&gt;
Answering question 2.&lt;BR /&gt;
&lt;BR /&gt;
Yes, on your second example j is a macro var from compile-time.&lt;BR /&gt;
&lt;BR /&gt;
Answering question 3.&lt;BR /&gt;
&lt;BR /&gt;
From the syntax point of view, yes. Your code is correct.&lt;BR /&gt;
You are building 5 step cycle if-then within a 10 step cycle datastep (10x5 cycles)&lt;BR /&gt;
&lt;BR /&gt;
So you will get 10 datasteps with 5 if-then statements in each.&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Thu, 28 May 2009 15:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variables/m-p/37826#M7526</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-05-28T15:14:19Z</dc:date>
    </item>
  </channel>
</rss>

