<?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: a simple but tricky sas macro bug in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105147#M21938</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Macro code just a code generation tool. In your case the macro generates DATA step code. THEN the data step runs.&amp;nbsp; So there is no way for the macro code to see much less react to changes in the value of variables inside of datasets.&amp;nbsp; In your example A and B are just text strings to the macro processor.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 27 Aug 2012 18:31:05 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2012-08-27T18:31:05Z</dc:date>
    <item>
      <title>a simple but tricky sas macro bug</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105143#M21934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;dear all, I am learning SAS macro for my research recently and confronted a macro problem which looks like simple, but has been bothering me for couple of days.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The original data set looks like as following&lt;/P&gt;&lt;P&gt;a b&lt;/P&gt;&lt;P&gt;1 3&lt;/P&gt;&lt;P&gt;2 5&lt;/P&gt;&lt;P&gt;3 10&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to transform the data to this form&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;bc1 bc2 bc3&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried to use the attached code to accomplish this, but I got&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;bca&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;10&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code is as following,&lt;/P&gt;&lt;P&gt;Code: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%MACRO varlist(i=,content=);&lt;/P&gt;&lt;P&gt;dc&amp;amp;i=&amp;amp;content;&lt;/P&gt;&lt;P&gt;%MEND varlist;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;input a b;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 3&lt;/P&gt;&lt;P&gt;2 5&lt;/P&gt;&lt;P&gt;3 10&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test1(drop=a b);&lt;/P&gt;&lt;P&gt;set test;&lt;/P&gt;&lt;P&gt;%varlist(i=a,content=b);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Someone told me that the bug is due to the variable a is numerical. However, when I let a be strings, like "apple", "orange" and "banana", I still have the some problem. I guess it won't be very complicate to solve this bug, but I am struck with it. Thanks for you helps! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Aug 2012 17:47:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105143#M21934</guid>
      <dc:creator>tediest</dc:creator>
      <dc:date>2012-08-27T17:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: a simple but tricky sas macro bug</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105144#M21935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data ab;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input a b;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 3&lt;/P&gt;&lt;P&gt;2 5&lt;/P&gt;&lt;P&gt;3 10&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array bc {3} bc1-bc3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set ab;&lt;/P&gt;&lt;P&gt;&amp;nbsp; bc{a}=b;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop a b;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You don't need macro for this.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Aug 2012 17:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105144#M21935</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2012-08-27T17:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: a simple but tricky sas macro bug</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105145#M21936</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you don't have to use macro, you can try the code below:&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;input a b;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 3&lt;/P&gt;&lt;P&gt;2 5&lt;/P&gt;&lt;P&gt;3 10&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;options missing=' ';&lt;/P&gt;&lt;P&gt;data want(keep=b1-b3);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array _b(*) b1-b3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; _b(a)=b;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp; proc print;run;&lt;/P&gt;&lt;P&gt;options missing='.';&lt;/P&gt;&lt;P&gt;obs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b1&amp;nbsp;&amp;nbsp;&amp;nbsp; b2&amp;nbsp;&amp;nbsp;&amp;nbsp; b3&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;/P&gt;&lt;P&gt;3&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; 10&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Aug 2012 17:59:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105145#M21936</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-08-27T17:59:20Z</dc:date>
    </item>
    <item>
      <title>Re: a simple but tricky sas macro bug</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105146#M21937</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for you guys. This should solve me problem. Though I don't need macro now, I am still curious about why the macro does not work in the original code. Any hints? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Aug 2012 18:20:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105146#M21937</guid>
      <dc:creator>tediest</dc:creator>
      <dc:date>2012-08-27T18:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: a simple but tricky sas macro bug</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105147#M21938</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Macro code just a code generation tool. In your case the macro generates DATA step code. THEN the data step runs.&amp;nbsp; So there is no way for the macro code to see much less react to changes in the value of variables inside of datasets.&amp;nbsp; In your example A and B are just text strings to the macro processor.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Aug 2012 18:31:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105147#M21938</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-08-27T18:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: a simple but tricky sas macro bug</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105148#M21939</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If so, the values of B should not be passed to macro. In this case, only A is treated as string and B seems working well. That is something confusing me. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Aug 2012 18:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105148#M21939</guid>
      <dc:creator>tediest</dc:creator>
      <dc:date>2012-08-27T18:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: a simple but tricky sas macro bug</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105149#M21940</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;But the VALUES of B were not passed to the macro.&amp;nbsp; The macro just generated the text "dca=b".&amp;nbsp; Because of where it was placed in the data step this was then interpreted by regular SAS as an assignment statement. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The same as if you just submitted the generated code without using the macro:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data test1(drop=a b);&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;set test;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;dca=b;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Aug 2012 18:55:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105149#M21940</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-08-27T18:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: a simple but tricky sas macro bug</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105150#M21941</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; I see where it is wrong. Thanks a lot!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Aug 2012 19:14:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105150#M21941</guid>
      <dc:creator>tediest</dc:creator>
      <dc:date>2012-08-27T19:14:07Z</dc:date>
    </item>
    <item>
      <title>Re: a simple but tricky sas macro bug</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105151#M21942</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tom's answer says pretty much all. I would just add this...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As said Macro SAS works &lt;SPAN style="text-decoration: underline;"&gt;mostly&lt;/SPAN&gt; at compile time. That's where macro code/vars gets "solved".&lt;/P&gt;&lt;P&gt;So that's why there's no interaction with the run time phase, which comes next.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I say mostly, because you can actually "fiddle" with Macros at run time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;symput, symget, and other datastep macro functions allows you to manipulate Macro vars from the inside of the running datastep.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;More on this here:&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a003167025.htm" title="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a003167025.htm"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a003167025.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers from Portugal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Aug 2012 16:17:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105151#M21942</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2012-08-29T16:17:35Z</dc:date>
    </item>
    <item>
      <title>Re: a simple but tricky sas macro bug</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105152#M21943</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Daniel, thanks for the extension. I realized this issue when I explored along Tom's hints. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Aug 2012 01:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105152#M21943</guid>
      <dc:creator>tediest</dc:creator>
      <dc:date>2012-08-31T01:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: a simple but tricky sas macro bug</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105153#M21944</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi tediest,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I know Tom's answer solved your doubt. I am a newbie. Me too tried your code , you can get the result with the following code too.&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;input a b;&lt;BR /&gt;cards;&lt;BR /&gt;1 3&lt;BR /&gt;2 5&lt;BR /&gt;3 10&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc transpose data = tst prefix= bc out =test1(drop= a _NAME_);&lt;BR /&gt; var b;&lt;BR /&gt; by a;&lt;BR /&gt; id a;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data = test1; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Sep 2012 04:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105153#M21944</guid>
      <dc:creator>mimi</dc:creator>
      <dc:date>2012-09-07T04:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: a simple but tricky sas macro bug</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105154#M21945</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;oh, this procedure is really handy. Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Sep 2012 20:32:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-simple-but-tricky-sas-macro-bug/m-p/105154#M21945</guid>
      <dc:creator>tediest</dc:creator>
      <dc:date>2012-09-07T20:32:27Z</dc:date>
    </item>
  </channel>
</rss>

