<?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: Utilizing Macro References in An Array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Utilizing-Macro-References-in-An-Array/m-p/246979#M46266</link>
    <description>&lt;P&gt;I suspect that it tokenizer is splitting BIN_%.... into two tokens and making your generated SAS code invalid.&lt;/P&gt;
&lt;P&gt;Usually I just assign the generated word to macro variable and then use the vlaue of the macro variable. &amp;nbsp;But you could also try wrapping it inside of a %UNQUOTE() function so that SAS knows to treat it as one word.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for example you could generate the BIN_.... name into a macro variable called BIN and then use it as the name for your ARRAY. You could also simplify the logic of your DO loop and convert your IF/THEN/ELSE to just an assignment statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let bin=BIN_%SCAN(&amp;amp;DATA,&amp;amp;i);
%let nbins=&amp;amp;&amp;amp;Count%SCAN(&amp;amp;DATA,&amp;amp;i);
ARRAY &amp;amp;BIN [&amp;amp;nbins] ;
DO i = 1 TO dim(&amp;amp;bin);
  &amp;amp;bin(i) = NOT (%SCAN(&amp;amp;DATA,&amp;amp;i)(i) = '') ;
END;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Jan 2016 21:00:14 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2016-01-29T21:00:14Z</dc:date>
    <item>
      <title>Utilizing Macro References in An Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Utilizing-Macro-References-in-An-Array/m-p/246969#M46264</link>
      <description>&lt;P&gt;In the macro this is what I have:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA %SCAN(&amp;amp;DATA,&amp;amp;i); &lt;BR /&gt; SET %SCAN(&amp;amp;DATA,&amp;amp;i); &lt;BR /&gt; ARRAY %SCAN(&amp;amp;DATA,&amp;amp;i)[*] &amp;amp;&amp;amp;List_Social;&lt;BR /&gt; ARRAY BIN_%SCAN(&amp;amp;DATA,&amp;amp;i)[*] BIN_%SCAN(&amp;amp;DATA,&amp;amp;i)1 - BIN_%SCAN(&amp;amp;DATA,&amp;amp;i)&amp;amp;&amp;amp;Count%SCAN(&amp;amp;DATA,&amp;amp;i);&lt;BR /&gt; DO i = 1 TO &amp;amp;&amp;amp;Count%SCAN(&amp;amp;DATA,&amp;amp;i); &lt;BR /&gt; IF %SCAN(&amp;amp;DATA,&amp;amp;i)(i) = '' THEN BIN_%SCAN(&amp;amp;DATA,&amp;amp;i)(i) = 0;&lt;BR /&gt; ELSE BIN_%SCAN(&amp;amp;DATA,&amp;amp;i)(i) = 1;&lt;BR /&gt; END;&lt;BR /&gt; RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Outside of the macro the code resolves to this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA Social; &lt;BR /&gt; SET Social; &lt;BR /&gt; ARRAY Social[&amp;amp;CountSocial] &amp;amp;List_Social;&lt;BR /&gt; ARRAY BIN_Social[&amp;amp;CountSocial] BIN_Social1 - BIN_Social&amp;amp;CountSocial;&lt;BR /&gt; DO i = 1 TO &amp;amp;CountSocial; &lt;BR /&gt; IF Social(i) = '' THEN BIN_Social(i) = 0;&lt;BR /&gt; ELSE BIN_Social(i) = 1;&lt;BR /&gt; END;&lt;BR /&gt; RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When it runs in the macro, SAS freaks out when it gets to the '&amp;amp;' symbols and does not treat them as macro variables. &amp;nbsp;Any help is appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2016 20:13:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Utilizing-Macro-References-in-An-Array/m-p/246969#M46264</guid>
      <dc:creator>Katie</dc:creator>
      <dc:date>2016-01-29T20:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: Utilizing Macro References in An Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Utilizing-Macro-References-in-An-Array/m-p/246974#M46265</link>
      <description>Can you say more about *how* SAS freaks out?  Are you getting macro variable not resolved messages?  What values do the macro vars have?Maybe turn on options MPRINT and call the macro, then add that log.</description>
      <pubDate>Fri, 29 Jan 2016 20:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Utilizing-Macro-References-in-An-Array/m-p/246974#M46265</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2016-01-29T20:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: Utilizing Macro References in An Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Utilizing-Macro-References-in-An-Array/m-p/246979#M46266</link>
      <description>&lt;P&gt;I suspect that it tokenizer is splitting BIN_%.... into two tokens and making your generated SAS code invalid.&lt;/P&gt;
&lt;P&gt;Usually I just assign the generated word to macro variable and then use the vlaue of the macro variable. &amp;nbsp;But you could also try wrapping it inside of a %UNQUOTE() function so that SAS knows to treat it as one word.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for example you could generate the BIN_.... name into a macro variable called BIN and then use it as the name for your ARRAY. You could also simplify the logic of your DO loop and convert your IF/THEN/ELSE to just an assignment statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let bin=BIN_%SCAN(&amp;amp;DATA,&amp;amp;i);
%let nbins=&amp;amp;&amp;amp;Count%SCAN(&amp;amp;DATA,&amp;amp;i);
ARRAY &amp;amp;BIN [&amp;amp;nbins] ;
DO i = 1 TO dim(&amp;amp;bin);
  &amp;amp;bin(i) = NOT (%SCAN(&amp;amp;DATA,&amp;amp;i)(i) = '') ;
END;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2016 21:00:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Utilizing-Macro-References-in-An-Array/m-p/246979#M46266</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-01-29T21:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: Utilizing Macro References in An Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Utilizing-Macro-References-in-An-Array/m-p/246997#M46272</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37812"&gt;@Katie﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think, the primary issue is the construct&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;&amp;amp;Count%SCAN(&amp;amp;DATA,&amp;amp;i)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please try and replace both occurrences of it&amp;nbsp;by&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%unquote(%superq(Count%SCAN(&amp;amp;DATA,&amp;amp;i)))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Actually, in the second occurrence (the "TO" value of the DO loop) you could omit the %UNQUOTE(), but it does no harm anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;Explanation: The idea is that after %SCAN(&amp;amp;DATA,&amp;amp;i) resolves to something like Social, %SUPERQ will return the content of macro variable CountSocial (this macro variable must exist in your macro, though). In the first occurrence of the problematic construct, the value contained in CountSocial, say 17, needs to be prefixed with&amp;nbsp;BIN_%SCAN(&amp;amp;DATA,&amp;amp;i), i.e. BIN_Social. This requires unquoting, because otherwise an invisible character (from macro quoting) would hang&amp;nbsp;between "BIN_Social" and "17" and the data step compiler wouldn't like that.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2016 22:31:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Utilizing-Macro-References-in-An-Array/m-p/246997#M46272</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-29T22:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: Utilizing Macro References in An Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Utilizing-Macro-References-in-An-Array/m-p/246999#M46273</link>
      <description>&lt;P&gt;That's probably it. &amp;nbsp;Again it is easier to just use another variable and break the step into pieces. &amp;nbsp;Has the added benifit when the value is needed in multiple places of making the code easier to read.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let countvar=Count%SCAN(&amp;amp;DATA,&amp;amp;i);
%let count=&amp;amp;&amp;amp;&amp;amp;countvar;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jan 2016 22:45:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Utilizing-Macro-References-in-An-Array/m-p/246999#M46273</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-01-29T22:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: Utilizing Macro References in An Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Utilizing-Macro-References-in-An-Array/m-p/247001#M46274</link>
      <description>&lt;P&gt;Yes, sure. I would have coded that macro differently, too. With my suggestion I tried just to fix the issue without changing too much of the existing code.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2016 22:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Utilizing-Macro-References-in-An-Array/m-p/247001#M46274</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-29T22:52:54Z</dc:date>
    </item>
  </channel>
</rss>

