<?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 Using macro as part of variable name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-as-part-of-variable-name/m-p/827769#M326969</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I have code like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let year=2019;
proc sql;
    select price as price_&amp;amp;year
    from my_data;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;With this the name of variable is price_2019 like I wanted. However, is there a way to use that specific macro variable same way to get other years too? I tried to use price_&amp;amp;year-1 but it didn't work. It feels stupid to make own macro for every year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Aug 2022 08:17:04 GMT</pubDate>
    <dc:creator>splt</dc:creator>
    <dc:date>2022-08-09T08:17:04Z</dc:date>
    <item>
      <title>Using macro as part of variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-as-part-of-variable-name/m-p/827769#M326969</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I have code like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let year=2019;
proc sql;
    select price as price_&amp;amp;year
    from my_data;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;With this the name of variable is price_2019 like I wanted. However, is there a way to use that specific macro variable same way to get other years too? I tried to use price_&amp;amp;year-1 but it didn't work. It feels stupid to make own macro for every year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2022 08:17:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-as-part-of-variable-name/m-p/827769#M326969</guid>
      <dc:creator>splt</dc:creator>
      <dc:date>2022-08-09T08:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro as part of variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-as-part-of-variable-name/m-p/827772#M326971</link>
      <description>&lt;P&gt;Since the macro language has only datatype text (which means that "2019 - 1" is not a formula, but just a string of characters), you need to force it to perform calculations by using %EVAL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;price_%eval(&amp;amp;year - 1)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let year = 2019;

data test;
price_&amp;amp;year = 1;
price_%eval(&amp;amp;year - 1)  = 2;
run;

proc print data=test noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;price_2019	price_2018
1	2
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2022 08:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-as-part-of-variable-name/m-p/827772#M326971</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-08-09T08:27:11Z</dc:date>
    </item>
  </channel>
</rss>

