<?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: using macro variables as values in data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/using-macro-variables-as-values-in-data-set/m-p/870544#M343830</link>
    <description>&lt;P&gt;You have to actually reference the macro variables you have defined. In WAY3 you do not reference any of B1 to B4.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/****Way3******/
%macro RRR;
%do i=1 %to &amp;amp;n.;
b&amp;amp;i.=&amp;amp;&amp;amp;b&amp;amp;i.;
%end;
%mend RRR;

data want3;
%RRR;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can skip a lot of the macro code and just use data step functions instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/****Way4******/
data want;
  array b [4];
  do i=1 to dim(b);
    b[i]=symgetn(cats('b',i));
  end;
  drop i;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 19 Apr 2023 13:35:52 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-04-19T13:35:52Z</dc:date>
    <item>
      <title>using macro variables as values in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-macro-variables-as-values-in-data-set/m-p/870520#M343818</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;What is the reason that way3 is not working and I get&amp;nbsp; data set with null values?&lt;/P&gt;
&lt;P&gt;What is the way to repair way3 in order to get desired results?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/***Way1****/
/***Way1****/
/***Way1****/
data want1;
b1=1;
b2=11;
b3=12;
b4=13;
Run;

/****Way2******/
/****Way2******/
/****Way2******/
%let b1=1;
%let b2=11;
%let b3=12;
%let b4=13;
data want2;
b1=&amp;amp;b1.;
b2=&amp;amp;b2.;
b3=&amp;amp;b3.;
b4=&amp;amp;b4.;
Run;

/****Way3******/
/****Way3******/
/****Way3******/
%let b1=1;
%let b2=11;
%let b3=12;
%let b4=13;

%macro RRR;
%do i=1 %to &amp;amp;n.;
b&amp;amp;i.=b&amp;amp;i.;
%end;
%mend RRR;

data want3;
%RRR;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 10:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-macro-variables-as-values-in-data-set/m-p/870520#M343818</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-04-19T10:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: using macro variables as values in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-macro-variables-as-values-in-data-set/m-p/870522#M343820</link>
      <description>&lt;P&gt;You do not have any specification of what &amp;amp;n is in your code.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 11:02:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-macro-variables-as-values-in-data-set/m-p/870522#M343820</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2023-04-19T11:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: using macro variables as values in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-macro-variables-as-values-in-data-set/m-p/870526#M343822</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Besides the &amp;amp;n problem mentioned by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;, your code vil not work, because you don't refer to a macro variable in the version 3 data step.&lt;/P&gt;
&lt;P&gt;Compare&amp;nbsp; version 2 to&amp;nbsp;&amp;nbsp;version 3:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;b4=&amp;amp;b4.; vs.  b&amp;amp;i.=b&amp;amp;i.;&lt;/LI-CODE&gt;
&lt;P&gt;This vill transfer the macro variables to data step variables:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;%let b1=1;
%let b2=11;
%let b3=12;
%let b4=13;

%macro RRR;
%do i=1 %to 4;
b&amp;amp;i.=&amp;amp;&amp;amp;b&amp;amp;i.;
%end;
%mend RRR;

data want3;
%RRR;
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 11:21:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-macro-variables-as-values-in-data-set/m-p/870526#M343822</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2023-04-19T11:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: using macro variables as values in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-macro-variables-as-values-in-data-set/m-p/870528#M343823</link>
      <description>&lt;P&gt;It seems to me the log is quite specific about what is wrong with WAY3. Did you look at the log? It appears that you did not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;WARNING: Apparent symbolic reference N not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &amp;amp;n.
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro RRR will stop executing.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you fix that, it always helps when running macros to precede the call to the macro with this command which turns on debugging options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So now with N assigned a value and the debugging option turned on, you will see this in the log&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;8866   data want3;
8867   %RRR;
MPRINT(RRR):   b1=b1;
MPRINT(RRR):   b2=b2;
MPRINT(RRR):   b3=b3;
MPRINT(RRR):   b4=b4;
8868   run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is not the same code as in WAY1. Can you see the difference?&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 11:49:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-macro-variables-as-values-in-data-set/m-p/870528#M343823</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-19T11:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: using macro variables as values in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-macro-variables-as-values-in-data-set/m-p/870532#M343825</link>
      <description>&lt;P&gt;sorry n=4,&lt;/P&gt;
&lt;P&gt;still data set is with null values&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/****Way3******/
/****Way3******/
/****Way3******/
%let b1=1;
%let b2=11;
%let b3=12;
%let b4=13;

%macro RRR;
%do i=1 %to 4;
b&amp;amp;i.=b&amp;amp;i.;
%end;
%mend RRR;

data want3;
%RRR;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Apr 2023 11:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-macro-variables-as-values-in-data-set/m-p/870532#M343825</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-04-19T11:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: using macro variables as values in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-macro-variables-as-values-in-data-set/m-p/870533#M343826</link>
      <description>&lt;P&gt;I found the solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/****Way3******/
/****Way3******/
/****Way3******/
%let b1=1;
%let b2=11;
%let b3=12;
%let b4=13;

options mprint;
%macro RRR;
%do i=1 %to 4;
b&amp;amp;i.=&amp;amp;&amp;amp;b&amp;amp;i..;
%end;
%mend RRR;

data want3;
%RRR;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Apr 2023 11:52:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-macro-variables-as-values-in-data-set/m-p/870533#M343826</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-04-19T11:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: using macro variables as values in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-macro-variables-as-values-in-data-set/m-p/870544#M343830</link>
      <description>&lt;P&gt;You have to actually reference the macro variables you have defined. In WAY3 you do not reference any of B1 to B4.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/****Way3******/
%macro RRR;
%do i=1 %to &amp;amp;n.;
b&amp;amp;i.=&amp;amp;&amp;amp;b&amp;amp;i.;
%end;
%mend RRR;

data want3;
%RRR;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can skip a lot of the macro code and just use data step functions instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/****Way4******/
data want;
  array b [4];
  do i=1 to dim(b);
    b[i]=symgetn(cats('b',i));
  end;
  drop i;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Apr 2023 13:35:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-macro-variables-as-values-in-data-set/m-p/870544#M343830</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-19T13:35:52Z</dc:date>
    </item>
  </channel>
</rss>

