<?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: Dynamic macro variable access in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471191#M120665</link>
    <description>&lt;P&gt;The first line in this error shows me making an array of size &amp;amp;num_or which is what I'm trying to assign the macro variable list to.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3580 do j=1 to &amp;amp;num_OR;&lt;BR /&gt;3581 rulesUsed{j}=&amp;amp;&amp;amp;Item&amp;amp;j;&lt;BR /&gt;WARNING: Apparent symbolic reference J not resolved.&lt;BR /&gt;NOTE: Line generated by the macro variable "J".&lt;BR /&gt;1 &amp;amp;Item&amp;amp;&lt;BR /&gt;-&lt;BR /&gt;22&lt;BR /&gt;WARNING: Apparent symbolic reference ITEM not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference J not resolved.&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,&lt;BR /&gt;a numeric constant, a datetime constant, a missing value, INPUT, PUT.&lt;/P&gt;&lt;P&gt;3582 end;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Jun 2018 18:43:05 GMT</pubDate>
    <dc:creator>S420L</dc:creator>
    <dc:date>2018-06-18T18:43:05Z</dc:date>
    <item>
      <title>Dynamic macro variable access</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471183#M120661</link>
      <description>&lt;DIV class="votecell post-layout--left"&gt;&lt;DIV class="vote"&gt;&lt;DIV class="favoritecount"&gt;I've used call symputx to create a list of macro variables Item 1 to Item N and now I want to transfer them to an array in another datastep so that spot 1 in the array gets Item1, spot 2 gets Item2, etc.&lt;/DIV&gt;&lt;DIV class="favoritecount"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="favoritecount"&gt;&lt;PRE&gt;&lt;CODE&gt;do j=1 to &amp;amp;num_OR;
    rulesUsed{j}=&amp;amp;&amp;amp;Item&amp;amp;j;
    end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV class="favoritecount"&gt;&lt;SPAN&gt;I read that the double ampersand syntax is the way to reference macro variables like this but I keep getting all sorts of errors. I'm sure there's a simple way around this but I'm new to SAS and no document I've read through that's come up in searches mentions this exact type of problem.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="favoritecount"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 18 Jun 2018 18:06:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471183#M120661</guid>
      <dc:creator>S420L</dc:creator>
      <dc:date>2018-06-18T18:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic macro variable access</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471186#M120662</link>
      <description>&lt;P&gt;Can you please post the log that indicates those errors and your full code, sample data etc&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 18:12:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471186#M120662</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-18T18:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic macro variable access</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471190#M120664</link>
      <description>DATA _Null_;&lt;BR /&gt;do I = 1 to &amp;amp;num_or;&lt;BR /&gt;set CondensedOverrides4 nobs = num_or;&lt;BR /&gt;call symputx("Item" !! left(put(I,8.))&lt;BR /&gt;,"Rule", "G");&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;This is how I used call symputx to make a list of macro variables "Item1" through "Item&amp;amp;num_or"</description>
      <pubDate>Mon, 18 Jun 2018 18:40:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471190#M120664</guid>
      <dc:creator>S420L</dc:creator>
      <dc:date>2018-06-18T18:40:12Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic macro variable access</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471191#M120665</link>
      <description>&lt;P&gt;The first line in this error shows me making an array of size &amp;amp;num_or which is what I'm trying to assign the macro variable list to.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3580 do j=1 to &amp;amp;num_OR;&lt;BR /&gt;3581 rulesUsed{j}=&amp;amp;&amp;amp;Item&amp;amp;j;&lt;BR /&gt;WARNING: Apparent symbolic reference J not resolved.&lt;BR /&gt;NOTE: Line generated by the macro variable "J".&lt;BR /&gt;1 &amp;amp;Item&amp;amp;&lt;BR /&gt;-&lt;BR /&gt;22&lt;BR /&gt;WARNING: Apparent symbolic reference ITEM not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference J not resolved.&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,&lt;BR /&gt;a numeric constant, a datetime constant, a missing value, INPUT, PUT.&lt;/P&gt;&lt;P&gt;3582 end;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 18:43:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471191#M120665</guid>
      <dc:creator>S420L</dc:creator>
      <dc:date>2018-06-18T18:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic macro variable access</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471192#M120666</link>
      <description>&lt;P&gt;classic problem of timing of maco execution vs datastep execution&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 18:44:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471192#M120666</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-18T18:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic macro variable access</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471193#M120667</link>
      <description>I know they execute at different times but I am confused why this doesn't work since I have tried assigning &amp;amp;Item1 to spot 1 in the array and it works fine</description>
      <pubDate>Mon, 18 Jun 2018 18:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471193#M120667</guid>
      <dc:creator>S420L</dc:creator>
      <dc:date>2018-06-18T18:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic macro variable access</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471194#M120668</link>
      <description>&lt;P&gt;please post the full array code, let me try to adjust that to make it work plz&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 18:46:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471194#M120668</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-18T18:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic macro variable access</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471195#M120669</link>
      <description>&lt;P&gt;data ihopethisworks;&lt;BR /&gt;set condensedOverrides4;&lt;/P&gt;&lt;P&gt;array Target1 {&amp;amp;num_OR} T1-T%trim(&amp;amp;num_or);&lt;BR /&gt;array Target2 {&amp;amp;num_OR} Tar1-Tar%trim(&amp;amp;num_or);&lt;BR /&gt;array Override1 {&amp;amp;num_OR} O1-O%trim(&amp;amp;num_or);&lt;BR /&gt;array Override2 {&amp;amp;num_OR} Over1-Over%trim(&amp;amp;num_or);&lt;BR /&gt;array revised_score {&amp;amp;num_OR} Rev1-Rev%trim(&amp;amp;num_or);&lt;BR /&gt;array num_hits {&amp;amp;num_OR} H1-H%trim(&amp;amp;num_or);&lt;/P&gt;&lt;P&gt;array rulesUsed {&amp;amp;num_OR} $3 Rulez1-Rulez%trim(&amp;amp;num_or);&lt;/P&gt;&lt;P&gt;do j=1 to &amp;amp;num_OR;&lt;BR /&gt;rulesUsed{j}=&amp;amp;&amp;amp;Item&amp;amp;j;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;do j=1 to &amp;amp;num_OR;&lt;BR /&gt;Target1{j}=_35;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;do j=1 to &amp;amp;num_OR;&lt;BR /&gt;Target2{j}=_36;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;do j=1 to &amp;amp;num_OR;&lt;BR /&gt;Override1{j}=_37;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;do j=1 to &amp;amp;num_OR;&lt;BR /&gt;Override2{j}=_38;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;do j=1 to &amp;amp;num_OR;&lt;BR /&gt;revised_score{j}=_39;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;do j=1 to &amp;amp;num_OR;&lt;BR /&gt;num_hits{j}=_40;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the full datastep&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 18:49:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471195#M120669</guid>
      <dc:creator>S420L</dc:creator>
      <dc:date>2018-06-18T18:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic macro variable access</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471197#M120671</link>
      <description>&lt;P&gt;Here is a small and simpler demo that simulates your needs. Try to replicate in your code and message us back with your feedback&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let item1=a;
%let item2=b;
%let item3=c;
%let item4=d;
%let item5=d;

data w;
array t(5) $;
do j=1 to 5;
call symputx('j', j);
t{j}=resolve('&amp;amp;&amp;amp;Item&amp;amp;j');
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Jun 2018 19:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471197#M120671</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-18T19:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic macro variable access</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471200#M120673</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/216263"&gt;@S420L&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;DIV class="votecell post-layout--left"&gt;
&lt;DIV class="vote"&gt;
&lt;DIV class="favoritecount"&gt;I've used call symputx to create a list of macro variables Item 1 to Item N and now I want to transfer them to an array in another datastep so that spot 1 in the array gets Item1, spot 2 gets Item2, etc.&lt;/DIV&gt;
&lt;DIV class="favoritecount"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="favoritecount"&gt;
&lt;PRE&gt;&lt;CODE&gt;do j=1 to &amp;amp;num_OR;
    rulesUsed{j}=&amp;amp;&amp;amp;Item&amp;amp;j;
    end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV class="favoritecount"&gt;&lt;SPAN&gt;I read that the double ampersand syntax is the way to reference macro variables like this but I keep getting all sorts of errors. I'm sure there's a simple way around this but I'm new to SAS and no document I've read through that's come up in searches mentions this exact type of problem.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="favoritecount"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The value of the data step variable J has nothing to do with the value of the macro variable J.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro processor deals with any macro code or macro variable references and passes the resulting strings off to SAS to interpret as SAS code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if NUM_OR=4 and&amp;nbsp;&amp;nbsp;J=1 and ITEM=1 is 234 then you ran this data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do j=1 to 4;
    rulesUsed{j}=234;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which will just make 4 copies of the same value into the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 19:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471200#M120673</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-06-18T19:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic macro variable access</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471207#M120674</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/216263"&gt;@S420L&lt;/a&gt;&amp;nbsp;wrote:
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _Null_;
do I = 1 to &amp;amp;num_or;
set CondensedOverrides4 nobs = num_or;
call symputx("Item" !! left(put(I,8.))
,"Rule", "G");
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This is how I used call symputx to make a list of macro variables "Item1" through "Item&amp;amp;num_or"&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why are you setting all of the macro variables to the same value, Rule ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you already have the data in the dataset CondensedOverrides4 then just use those values. No need for macro variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=CondensedOverrides4 
  prefix=rulesUsed
  out=want (drop=_name_)
;
var rule ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code is only converting a max of &amp;amp;NUM_OR observations, even if there are more in the dataset.&amp;nbsp; Is the macro variable NUM_OR some type of upper bound on the maximum number of rules you can handle?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or are you just confusing the macro variable NUM_OR with the data step variable NUM_OR which will be set by the NOBS option on the SET statement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 19:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471207#M120674</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-06-18T19:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic macro variable access</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471209#M120675</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;%do j = 1 %to &amp;amp;num_or;
  rulesUsed[&amp;amp;j.] = &amp;amp;&amp;amp;item&amp;amp;j;
%end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The macro approach seems to work, the way you suggested does result in a dataset but gives the previous name of the variable rather than its actual value, kinda weird I can't figure out why.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 19:36:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471209#M120675</guid>
      <dc:creator>S420L</dc:creator>
      <dc:date>2018-06-18T19:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic macro variable access</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471215#M120677</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/216263"&gt;@S420L&lt;/a&gt;&amp;nbsp; Hi, First off, Are you working in a production environment on a business deliverable or playing for knowledge like me. The approach we are discussing is all about fun and strictly not even close if you the situation is the former.&amp;nbsp; In that case , we should be paying to attention to wiser advice from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;and making it to really work in prod server.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My intent here was to show us(you and me) that it is possible to make it macro resolve during data step execution. That was all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, did you exactly replicate my code with the call symputx and resolve as demonstrated?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 19:48:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/471215#M120677</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-18T19:48:06Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic macro variable access</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/472150#M121010</link>
      <description>&lt;P&gt;I'm using SAS enterprise to make a business deliverable, while I don't have direct server access (I'm literally the only person in my department that can program at all, making something for them to give to the systems people) I obviously would like it to work in a production environment so that other programmers don't have to waste their time redoing things.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No I didn't add the part with resolve in I will try that now. Will the macro variable approach not work in a server environment?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jun 2018 15:25:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-macro-variable-access/m-p/472150#M121010</guid>
      <dc:creator>S420L</dc:creator>
      <dc:date>2018-06-21T15:25:21Z</dc:date>
    </item>
  </channel>
</rss>

