<?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: How to refer to a variable depending on the value of macrovariable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397594#M96103</link>
    <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884" target="_self"&gt;&lt;SPAN class="login-bold"&gt;ballardw&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thank you, I used the 'vvalue'! The question is why the next code is not functioning and is it possible to manage&amp;nbsp;it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;

	EPOCH='TREATMENT 3';
	period_N=substr(EPOC,11,1);
	call symputx('TP',period_N);

	ABC3X='Variant 3';
	ABC5X='Variant 5';&lt;BR /&gt;
	X= vvaluex(cats('ABC',"&amp;amp;TP.",'X'));

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Sep 2017 20:02:18 GMT</pubDate>
    <dc:creator>DmytroYermak</dc:creator>
    <dc:date>2017-09-20T20:02:18Z</dc:date>
    <item>
      <title>How to refer to a variable depending on the value of macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397559#M96090</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please advise in the following case. I have to refer to a variable depending on the value of macrovariable. Please see below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I receive ERROR in the log:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;X=ABC&amp;amp;TR.X;&lt;BR /&gt;     ----&lt;BR /&gt;&lt;/CODE&gt;WARNING: Apparent symbolic reference TR not resolved. &lt;/PRE&gt;&lt;P&gt;The code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;

	E='3';
	call symputx('TR',E);
		
	ABC3X='Variant 3';
	ABC5X='Variant 5';

	X=ABC&amp;amp;TR.X;

	put &amp;amp;TR.;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can it be resolved?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2017 18:12:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397559#M96090</guid>
      <dc:creator>DmytroYermak</dc:creator>
      <dc:date>2017-09-20T18:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to refer to a variable depending on the value of macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397570#M96095</link>
      <description>&lt;P&gt;First SAS compiles your DATA step (attempting to resolve the macro variable). &amp;nbsp;It did not succeed because you have not yet defined it. &amp;nbsp;Had it succeeded, SAS would have next run the DATA step. &amp;nbsp;It is only then that the macro is set to a value. &amp;nbsp;So you need to use SYMPUTX in one DATA step and first use the value in the next step. &amp;nbsp;Alternatively, base your code on arrays or some other way that does not require macros.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2017 18:48:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397570#M96095</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-09-20T18:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to refer to a variable depending on the value of macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397573#M96096</link>
      <description>&lt;P&gt;This can't happen within a DATA step.&amp;nbsp; SAS has to be able to look through the DATA step statements, check for syntax errors, and set up storage space for every variable used within the DATA step ... before actually executing any of the code.&amp;nbsp; There's no way to set up storage space for ABC&amp;amp;TR.X at that point, because the value of &amp;amp;TR is unknown until the DATA step actually executes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a macro application, there is no problem:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let E = 3;&lt;/P&gt;
&lt;P&gt;%let&amp;nbsp;TR = &amp;amp;e;&lt;/P&gt;
&lt;P&gt;%let ABC3X = Variant 3;&lt;/P&gt;
&lt;P&gt;%let ABC5X = Variant 5;&lt;/P&gt;
&lt;P&gt;%let X = ABC&amp;amp;TR.X;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or possibly (depending on the intended result):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let X = &amp;amp;&amp;amp;ABC&amp;amp;TR.X;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2017 18:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397573#M96096</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-20T18:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to refer to a variable depending on the value of macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397588#M96100</link>
      <description>&lt;P&gt;This would be one way to accomplish what you attempted inside a data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test;
	E='3';
	ABC3X='Variant 3';
	ABC5X='Variant 5';
	X= vvaluex(cats('ABC',E,'X'));
run;&lt;/PRE&gt;
&lt;P&gt;The Vvaluex function will take either a variable value or expression that returns a variable name and find the value to assign to the target variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I mentioned in the prior question about creating a macro variable in data step it is seldom needed to attempt to use that value inside the same data step, and most attempts will fail due to compliation and order of creation of the variables.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2017 19:47:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397588#M96100</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-20T19:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to refer to a variable depending on the value of macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397594#M96103</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884" target="_self"&gt;&lt;SPAN class="login-bold"&gt;ballardw&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thank you, I used the 'vvalue'! The question is why the next code is not functioning and is it possible to manage&amp;nbsp;it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;

	EPOCH='TREATMENT 3';
	period_N=substr(EPOC,11,1);
	call symputx('TP',period_N);

	ABC3X='Variant 3';
	ABC5X='Variant 5';&lt;BR /&gt;
	X= vvaluex(cats('ABC',"&amp;amp;TP.",'X'));

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2017 20:02:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397594#M96103</guid>
      <dc:creator>DmytroYermak</dc:creator>
      <dc:date>2017-09-20T20:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to refer to a variable depending on the value of macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397596#M96104</link>
      <description>&lt;P&gt;Same answer as before. &amp;nbsp;The macro is not set to a value at compile time. &amp;nbsp;It is set later at run time.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2017 20:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397596#M96104</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-09-20T20:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to refer to a variable depending on the value of macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397597#M96105</link>
      <description>Please explain the need for creating a macro variable and using it in the same data step. Please. 


If this is just a test of creating a macro variable then you have demonstrated that creating it and attempting to use it this way will not work. The macro variable would be available in another data step if needed. Though for the specific test you have chosen to demonstrate the use there would be no need for a macro variable at all.</description>
      <pubDate>Wed, 20 Sep 2017 20:13:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397597#M96105</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-20T20:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to refer to a variable depending on the value of macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397604#M96106</link>
      <description>Thank you. It was my misunderstanding - it seems I have to look into macros much deeper now ). I accepted your solution and using it in one training task that I'm doing now.</description>
      <pubDate>Wed, 20 Sep 2017 20:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397604#M96106</guid>
      <dc:creator>DmytroYermak</dc:creator>
      <dc:date>2017-09-20T20:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to refer to a variable depending on the value of macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397605#M96107</link>
      <description>&lt;P&gt;The principal is this:&amp;nbsp; data step compilation (translate from sas statement to machine instructions) must precede data step execution (i.e. the implementation of machine instructions).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That means the SAS data step Compiler needs the value of macrovar TP in order to compile the &lt;EM&gt;&lt;STRONG&gt;X=vvalue ...&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;statement.&amp;nbsp; But macrovar TP will not be assigned a value until the data step executes (i.e. when the call symputx statement is already compiled &lt;EM&gt;&lt;STRONG&gt;and executed&lt;/STRONG&gt;&lt;/EM&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However,&amp;nbsp;your sample program doesn't even need macrovars.&amp;nbsp; Drop the call symputx statement and change&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; X&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;vvaluex&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;cats&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'ABC'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"&amp;amp;TP."&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'X'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;X&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;vvaluex&lt;/SPAN&gt;(&lt;SPAN class="token function"&gt;cats&lt;/SPAN&gt;(&lt;SPAN class="token string"&gt;'ABC',N_period&lt;/SPAN&gt;,&lt;SPAN class="token string"&gt;'X'&lt;/SPAN&gt;));&lt;/FONT&gt;&lt;BR /&gt;&lt;/SPAN&gt;or better yet, to&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;X&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;vvaluex&lt;/SPAN&gt;(&lt;SPAN class="token function"&gt;cats&lt;/SPAN&gt;(&lt;SPAN class="token string"&gt;'ABC'&lt;/SPAN&gt;,substr(epoch,11,1),&lt;SPAN class="token string"&gt;'X'&lt;/SPAN&gt;));&lt;/FONT&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;to&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2017 20:33:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/397605#M96107</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-09-20T20:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to refer to a variable depending on the value of macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/398371#M96361</link>
      <description>&lt;P&gt;Actually,&amp;nbsp; this is functioning as well:&lt;/P&gt;&lt;PRE&gt;symget(" ")&lt;/PRE&gt;&lt;P&gt;Different matter is that it is not needed here:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;

	E='3';
	call symputx('TR',E);
		
	ABC3X='Variant 3';
	ABC5X='Variant 5';

	X=vvaluex(cats('ABC',symget("TR"),'X'));

run;

proc print data=test; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I thought that the symget would not work here at all.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 13:44:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-refer-to-a-variable-depending-on-the-value-of/m-p/398371#M96361</guid>
      <dc:creator>DmytroYermak</dc:creator>
      <dc:date>2017-10-20T13:44:52Z</dc:date>
    </item>
  </channel>
</rss>

