<?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 do I get the value of a variable via its name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-get-the-value-of-a-variable-via-its-name/m-p/463727#M118191</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or you could&amp;nbsp;generate the&amp;nbsp;data set wih one Data Step only, although two sets of extra temporary variables are in need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   array y[4] $3. _temporary_ ('ANT' 'BEE' 'CAT' 'DOG');
   array _x[4] $3.;
   array x[4] $3.;
   drop _:;
   n = dim(y);
   do i=1 to n;
      do j=1 to comb(n, i);
         if j=1 then do k=1 to n;
            _x[k] = y[k];
         end;
         call lexcomb(j, i, of _x[*]);
         do k=1 to i;
            x[k] = _x[k];
         end;
         output;
      end;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 21 May 2018 11:05:59 GMT</pubDate>
    <dc:creator>jim_cai</dc:creator>
    <dc:date>2018-05-21T11:05:59Z</dc:date>
    <item>
      <title>how do I get the value of a variable via its name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-get-the-value-of-a-variable-via-its-name/m-p/457485#M115991</link>
      <description>&lt;P&gt;If a condition is met, I want to call missing of a set of variables whose members depend on the condition as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My hard coded program works but I cannot automate it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST;

ARRAY X [4] $3 ('ANT' 'BEE' 'CAT' 'DOG'); 
N=DIM(X);
DO U=1 TO N-1;
NCOMB=COMB(N,U ); 
DO I=1 TO NCOMB;   

CALL LEXCOMB(I, U, OF X[*]);
OUTPUT;
END;
END;
NFACT=FACT(N);
DO J=1 TO NFACT;
CALL ALLPERM(J,OF X[*]);
OUTPUT;
END;
RUN;

DATA TEST2;
SET TEST;

IF U=1 THEN CALL MISSING (OF X2-X4);
IF U=2 THEN CALL MISSING (OF %SYSFUNC(CATT(X3-,X,%EVAL(3+1)))); 
IF U=3 THEN CALL MISSING (X4);
HELP=VVALUEX(CATT("X",%SYSFUNC(SUM(3,1))));

RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The CALL MISSING part does not accept in the %eval bracket the numeric variable but complains that a char var&amp;nbsp;is passed.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 19:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-get-the-value-of-a-variable-via-its-name/m-p/457485#M115991</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2018-04-25T19:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: how do I get the value of a variable via its name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-get-the-value-of-a-variable-via-its-name/m-p/457492#M115993</link>
      <description>&lt;P&gt;The DATA step cannot use CAT functions to generate the code that is part of the same DATA step.&amp;nbsp; A simpler version would overcome the initial problem:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token keyword"&gt;IF&lt;/SPAN&gt; U&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;THEN&lt;/SPAN&gt; CALL &lt;SPAN class="token function"&gt;MISSING&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;OF X3&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;X&lt;SPAN class="token macroname"&gt;%EVAL&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&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;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;I'm not sure what you're trying to get&amp;nbsp;into the HELP formula, but this might be a little closer:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;help = X%eval(3+1);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;The macro functions do not execute as the DATA step executes.&amp;nbsp; They execute before the DATA step begins, and generate the statements that become part of the DATA step code.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 20:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-get-the-value-of-a-variable-via-its-name/m-p/457492#M115993</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-25T20:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: how do I get the value of a variable via its name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-get-the-value-of-a-variable-via-its-name/m-p/457496#M115994</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it doesn´t work neither when putting&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10pt;"&gt;&lt;FONT color="#000000"&gt;IF U=2 THEN CALL MISSING (OF X3-X%EVAL(U+1));&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10pt;"&gt;&lt;FONT color="#000000"&gt;The code deosn't like the reference to the numeric variable U&lt;/FONT&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;</description>
      <pubDate>Wed, 25 Apr 2018 20:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-get-the-value-of-a-variable-via-its-name/m-p/457496#M115994</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2018-04-25T20:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: how do I get the value of a variable via its name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-get-the-value-of-a-variable-via-its-name/m-p/457501#M115996</link>
      <description>&lt;P&gt;You're right, it definitely doesn't work for that.&amp;nbsp; DATA step statements cannot change from one observation to the next.&amp;nbsp; Whatever the statement is, it remains the same for all observations.&amp;nbsp; You might need a loop, more like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array x {*} X: ;&lt;/P&gt;
&lt;P&gt;do k=3 to u+1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; call missing (x{k});&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 20:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-get-the-value-of-a-variable-via-its-name/m-p/457501#M115996</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-25T20:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: how do I get the value of a variable via its name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-get-the-value-of-a-variable-via-its-name/m-p/457507#M116000</link>
      <description>Perfect. Thanks.&lt;BR /&gt;If you have an idea to achieve my goal within the first permutation generating data set... Feel free to excel</description>
      <pubDate>Wed, 25 Apr 2018 20:19:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-get-the-value-of-a-variable-via-its-name/m-p/457507#M116000</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2018-04-25T20:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: how do I get the value of a variable via its name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-get-the-value-of-a-variable-via-its-name/m-p/457625#M116037</link>
      <description>&lt;P&gt;It has worked out. Thank you again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The final code is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST;

ARRAY X [4] $3 ('ANT' 'BEE' 'CAT' 'DOG'); 
N=DIM(X);
DO U=1 TO N-1;
NCOMB=COMB(N,U ); 
DO I=1 TO NCOMB;   

CALL LEXCOMB(I, U, OF X[*]);
OUTPUT;
END;
END;
NFACT=FACT(N);
DO J=1 TO NFACT;
CALL ALLPERM(J,OF X[*]);
OUTPUT;
END;
RUN;

DATA TEST2;
SET TEST;
ARRAY X{*} X:;

DO K=2 TO DIM(X);
IF U LT K THEN CALL MISSING (X{K});
END;

HELP=VVALUEX(CATT("X",%SYSFUNC(SUM(3,1))));

RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="OUTPUT.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20152i917A62674CC90F04/image-size/large?v=v2&amp;amp;px=999" role="button" title="OUTPUT.png" alt="OUTPUT.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 08:07:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-get-the-value-of-a-variable-via-its-name/m-p/457625#M116037</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2018-04-26T08:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: how do I get the value of a variable via its name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-get-the-value-of-a-variable-via-its-name/m-p/463727#M118191</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or you could&amp;nbsp;generate the&amp;nbsp;data set wih one Data Step only, although two sets of extra temporary variables are in need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   array y[4] $3. _temporary_ ('ANT' 'BEE' 'CAT' 'DOG');
   array _x[4] $3.;
   array x[4] $3.;
   drop _:;
   n = dim(y);
   do i=1 to n;
      do j=1 to comb(n, i);
         if j=1 then do k=1 to n;
            _x[k] = y[k];
         end;
         call lexcomb(j, i, of _x[*]);
         do k=1 to i;
            x[k] = _x[k];
         end;
         output;
      end;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 May 2018 11:05:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-get-the-value-of-a-variable-via-its-name/m-p/463727#M118191</guid>
      <dc:creator>jim_cai</dc:creator>
      <dc:date>2018-05-21T11:05:59Z</dc:date>
    </item>
  </channel>
</rss>

