Get values of Macro Variables in a SAS Table
<p>I have a set of input macro variables in SAS. They are dynamic and generated based on the user selection in a sas stored process.</p>

<pre><code>For example:There are 10 input values 1 to 10.
The name of the macro variable is VAR_. If a user selects 2,5,7 then 4 macro variables are created. 
&amp;VAR_0=3;
&amp;VAR_=2;
&amp;VAR_1=5;
&amp;VAR_2=7;
</code></pre>

<p>The first one with suffix 0 provides the count. The next 3 provides the values.</p>

<p>Note:If a user select only one value then only one macro variable is created. For example If a user selects 9 then &amp;var_=9; will be created. There will not be any count macro variable. 
I am trying to create a sas table using these variables.</p>

<p>It should be like this</p>

<pre><code>OBS    VAR
-----------
1      2
2      5
3      7
-----------
</code></pre>

<p>This is what I tried. Not sure if this is the right way to do approach it.
It doesn't give me a final solution but I can atleast get the name of the macro variables in a table. How can I get their values ?</p>

<pre><code>data tbl1;
do I=1 to &amp;var_0;
VAR=CAT('&amp;VAR_',I-1);
OUTPUT;
END;
RUN;
PROC SQL;
CREATE TABLE TBL2 AS 
SELECT I,
CASE WHEN VAR= '&amp;VAR_0' THEN '&amp;VAR_' ELSE VAR END AS VAR
from TBL1;
QUIT;
</code></pre>

<p>Thank You for your help.</p>

<p>Jay</p>