<?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: Dynamic variable name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-variable-name/m-p/340566#M77851</link>
    <description>&lt;P&gt;thanks!!!&lt;/P&gt;</description>
    <pubDate>Mon, 13 Mar 2017 19:37:28 GMT</pubDate>
    <dc:creator>Rakeon</dc:creator>
    <dc:date>2017-03-13T19:37:28Z</dc:date>
    <item>
      <title>Dynamic variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-variable-name/m-p/340536#M77834</link>
      <description>&lt;P&gt;Hi ,&lt;BR /&gt;I create this data set:&lt;/P&gt;
&lt;PRE&gt;data temp;
 do i=1 to 5;
    a1=999;
    a2=999;
    a3=999;
    ...
   a10 =999;
   output;
 end;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;is there a better solution that create a second do-loop inside the first do-loop?&lt;BR /&gt;&lt;BR /&gt;for example like this:&lt;/P&gt;
&lt;PRE&gt;data temp;
 do i=1 to 10;
  do j=1 to 10;&lt;BR /&gt;   call symput("index",j);&lt;BR /&gt;   a&amp;amp;index=999;
  end;&lt;BR /&gt;  output;&lt;BR /&gt; end;
run;&lt;/PRE&gt;
&lt;P&gt;The last example, doesn't work, because it doesn't recognize the index variable.&lt;BR /&gt;&lt;BR /&gt;Is there some solution?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 18:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-variable-name/m-p/340536#M77834</guid>
      <dc:creator>Rakeon</dc:creator>
      <dc:date>2017-03-13T18:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-variable-name/m-p/340539#M77843</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
array vars {*} a1-a10;
do i = 1 to 5;
  do j = 1 to dim(vars);
    vars{j} = 999;
  end;
end;
drop j;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Mar 2017 18:33:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-variable-name/m-p/340539#M77843</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-13T18:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-variable-name/m-p/340543#M77845</link>
      <description>&lt;P&gt;SInce your new variables are constant, a better solution would not nest loops:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;retain a1-a10 999;&lt;/P&gt;
&lt;P&gt;do i=1 to 5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To answer your original question, no there is no solution.&amp;nbsp; SAS does not let you change what "a&amp;amp;index" resolves to, as the DATA step executes.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 18:43:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-variable-name/m-p/340543#M77845</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-13T18:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-variable-name/m-p/340566#M77851</link>
      <description>&lt;P&gt;thanks!!!&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 19:37:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-variable-name/m-p/340566#M77851</guid>
      <dc:creator>Rakeon</dc:creator>
      <dc:date>2017-03-13T19:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-variable-name/m-p/340567#M77852</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24745"&gt;@Rakeon&lt;/a&gt;&amp;nbsp;please mark the question as answered.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 19:44:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-variable-name/m-p/340567#M77852</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-13T19:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-variable-name/m-p/340595#M77865</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;A slightly more interesting problem;

Generating 10 observations with a random number of variables

Minimum number of variables is 1(a1) max is 5(a1-a5)

This is trivial in IML or R.

  n &amp;lt;- as.integer(5*runif(1)) +1;
  runif(n);

&amp;gt; n &amp;lt;- as.integer(5*runif(1)) +1;
  runif(n);
[1] 0.13442659 0.07485726 0.22734428 0.84948492
&amp;gt;

HAVE a random number between 1 and 5
========================================

    n=int(5*uniform(5739)) + 1;

  Note N could be meta data

WANT  Suppose the random n is 3
===============================

Up to 40 obs from want total obs=10

Obs       A1         A2         A3

  1    0.39041    0.51861    0.19275
  2    0.13243    0.54758    0.86705
  3    0.89960    0.18865    0.46915
  4    0.62604    0.15337    0.34970
  5    0.50958    0.16918    0.61778
  6    0.81300    0.88339    0.36657
  7    0.79296    0.56760    0.66014
  8    0.37525    0.19073    0.66443
  9    0.70009    0.31034    0.72677
 10    0.56065    0.93989    0.41765

SOLUTION
========

data _null_;
  n=int(5*uniform(5739)) + 1;
  call symputx('dim',put(n,3.));
   rc=dosubl('
      data want(drop=rec i);
        array a[&amp;amp;dim.] a1-a&amp;amp;dim;
        do rec=1 to 10;
           do i=1 to &amp;amp;dim;
              a[i]=uniform(5733);
           end;
           output;
        end;
      run;quit;
   ');
  stop;
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Mar 2017 23:21:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-variable-name/m-p/340595#M77865</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-03-13T23:21:04Z</dc:date>
    </item>
  </channel>
</rss>

