<?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: Question about referencing a variable through its name as a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Question-about-referencing-a-variable-through-its-name-as-a/m-p/134778#M27368</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have a look at the documentation for the %MACRO statement PBUF or PARMBUF option or something like that.&amp;nbsp;&amp;nbsp;&amp;nbsp; However like &lt;A __default_attr="5253" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt; says its easier to use blank delimited variable list.&amp;nbsp; It's more like the way SAS works.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 03 Dec 2014 22:33:50 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2014-12-03T22:33:50Z</dc:date>
    <item>
      <title>Question about referencing a variable through its name as a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-referencing-a-variable-through-its-name-as-a/m-p/134771#M27361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How do I reference a variable via its string name?&amp;nbsp; Here's an example of what I mean.&amp;nbsp; Let's say I had the following variables:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;whole = "twohalfs";&lt;/P&gt;&lt;P&gt;twohalfs = "fourquarters";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and I wanted to have a macro whose input was whole, but could access the contents of twohalfs. I formatting aside, I would expect something like this to work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="xml" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14176354081299162" jivemacro_uid="_14176354081299162" modifiedtitle="true"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;%macro dostuff(whole);&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;output = &amp;amp;&amp;amp;whole;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;put output;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;%mend dostuff;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, when I run something like that, &amp;amp;whole resolves to "twohalfs".&amp;nbsp; But then there's no second resolution.&amp;nbsp; And I'm just left outputting twohalfs and not fourquarters.&amp;nbsp; But I want fourquartersI suspect that there's a simple way to do this.&amp;nbsp; Please let me know your thoughts, or if you have any further questions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Robert Starin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 19:37:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-referencing-a-variable-through-its-name-as-a/m-p/134771#M27361</guid>
      <dc:creator>rstarin</dc:creator>
      <dc:date>2014-12-03T19:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: Question about referencing a variable through its name as a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-referencing-a-variable-through-its-name-as-a/m-p/134772#M27362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%let whole = twohalfs;&lt;/P&gt;&lt;P&gt;%let twohalfs = fourquarters;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put atlast=&amp;amp;&amp;amp;&amp;amp;whole;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 19:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-referencing-a-variable-through-its-name-as-a/m-p/134772#M27362</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-12-03T19:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: Question about referencing a variable through its name as a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-referencing-a-variable-through-its-name-as-a/m-p/134773#M27363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The thing that isn't working for me is when I do it with the quotes.&amp;nbsp; I don't know how to use the string "twohalfs" and get the contents of the variable called twohalfs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you know how to do that?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 19:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-referencing-a-variable-through-its-name-as-a/m-p/134773#M27363</guid>
      <dc:creator>rstarin</dc:creator>
      <dc:date>2014-12-03T19:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Question about referencing a variable through its name as a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-referencing-a-variable-through-its-name-as-a/m-p/134774#M27364</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure if I have completely understand your need, but:&lt;/P&gt;&lt;P&gt;%let whole = "&amp;amp;twohalfs";&lt;/P&gt;&lt;P&gt;%let twohalfs = fourquarters;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put atlast=&amp;amp;whole;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;update:&lt;/P&gt;&lt;P&gt;Or in a step by step lagging mode:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let whole = %nrstr("&amp;amp;twohalfs");&lt;/P&gt;&lt;P&gt;%let twohalfs = fourquarters;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put atlast=%unquote(&amp;amp;whole);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 20:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-referencing-a-variable-through-its-name-as-a/m-p/134774#M27364</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-12-03T20:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: Question about referencing a variable through its name as a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-referencing-a-variable-through-its-name-as-a/m-p/134775#M27365</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think this may be what you're trying to do. You need to move the quotes to the place where they are needed.&amp;nbsp; If this is not what you want explain your goal better.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV style="font-family: Courier New; font-size: 11pt;"&gt;&lt;SPAN style="color: #008080; background-color: #ffffff;"&gt;&lt;STRONG&gt;32&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; whole = twohalfs;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008080; background-color: #ffffff;"&gt;&lt;STRONG&gt;33&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; twohalfs = fourquarters;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008080; background-color: #ffffff;"&gt;&lt;STRONG&gt;34&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008080; background-color: #ffffff;"&gt;&lt;STRONG&gt;35&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008080; background-color: #ffffff;"&gt;&lt;STRONG&gt;36&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #000080; background-color: #ffffff;"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; dostuff(whole);&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008080; background-color: #ffffff;"&gt;&lt;STRONG&gt;37&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output = &lt;/SPAN&gt;&lt;SPAN style="color: #800080; background-color: #ffffff;"&gt;"&amp;amp;&amp;amp;&amp;amp;whole"&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008080; background-color: #ffffff;"&gt;&lt;STRONG&gt;38&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put output=;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008080; background-color: #ffffff;"&gt;&lt;STRONG&gt;39&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #000080; background-color: #ffffff;"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; dostuff;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008080; background-color: #ffffff;"&gt;&lt;STRONG&gt;40&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008080; background-color: #ffffff;"&gt;&lt;STRONG&gt;41&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; options mprint=&lt;/SPAN&gt;&lt;SPAN style="color: #008080; background-color: #ffffff;"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008080; background-color: #ffffff;"&gt;&lt;STRONG&gt;42&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data _null_;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008080; background-color: #ffffff;"&gt;&lt;STRONG&gt;43&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %&lt;/SPAN&gt;&lt;STRONG style="color: #000000; background-color: #ffffff;"&gt;&lt;EM&gt;dostuff&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;(twohalfs);&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;MPRINT(DOSTUFF):&amp;nbsp;&amp;nbsp; output = &lt;/SPAN&gt;&lt;SPAN style="color: #800080; background-color: #ffffff;"&gt;"fourquarters"&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;MPRINT(DOSTUFF):&amp;nbsp;&amp;nbsp; put output=;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008080; background-color: #ffffff;"&gt;&lt;STRONG&gt;44&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;output=fourquarters&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 20:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-referencing-a-variable-through-its-name-as-a/m-p/134775#M27365</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2014-12-03T20:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: Question about referencing a variable through its name as a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-referencing-a-variable-through-its-name-as-a/m-p/134776#M27366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, I think I have done a poor job of explaining what I'm doing.&amp;nbsp; I am looking to have a macro with an unknown number of parameters, and then within the macro, create new variables based on the names of those parameters and the value of the variables that they reference.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I figured that to do this, I should bring the parameters in via a string list or an array, and then read them out to create and set the new variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am able to hardcode this functionality for one (or a known set of parameters)with something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro dostuff(a,b);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;amp;a._temp = &amp;amp;a;&lt;/P&gt;&lt;P&gt;&amp;amp;b._temp = &amp;amp;b;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend dostuff;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ONE = 1;&lt;/P&gt;&lt;P&gt;TWO = 2;&lt;/P&gt;&lt;P&gt;%dostuff(ONE,TWO);&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;&lt;/P&gt;&lt;P&gt;would yield ONEtemp = 1 and TWOtemp = 2.&amp;nbsp; However, when I pass with an array (like parts{*} ONE TWO), I am having trouble creating the new variable name, and when I pass with a string list (like "ONE,TWO"), I am having trouble referencing the value of the named variable.&amp;nbsp; So this question was originally in regards to how to do this with a string list -- but the array route (or any other) is fine with me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks very much for your help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Bob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 21:59:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-referencing-a-variable-through-its-name-as-a/m-p/134776#M27366</guid>
      <dc:creator>rstarin</dc:creator>
      <dc:date>2014-12-03T21:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Question about referencing a variable through its name as a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-referencing-a-variable-through-its-name-as-a/m-p/134777#M27367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Suppose you were to create this sort of macro:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%dostuff (varlist=ONE TWO THREE FOUR)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could certainly use the parameter inside a DATA step:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;array parts {*} &amp;amp;varlist;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Would it be helpful to learn how macro language could set up a %DO loop to process ONE, then TWO, then THREE, then FOUR?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 22:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-referencing-a-variable-through-its-name-as-a/m-p/134777#M27367</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-12-03T22:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Question about referencing a variable through its name as a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-referencing-a-variable-through-its-name-as-a/m-p/134778#M27368</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have a look at the documentation for the %MACRO statement PBUF or PARMBUF option or something like that.&amp;nbsp;&amp;nbsp;&amp;nbsp; However like &lt;A __default_attr="5253" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt; says its easier to use blank delimited variable list.&amp;nbsp; It's more like the way SAS works.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 22:33:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-referencing-a-variable-through-its-name-as-a/m-p/134778#M27368</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2014-12-03T22:33:50Z</dc:date>
    </item>
  </channel>
</rss>

