<?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: Macro to create number of variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-create-number-of-variables/m-p/868183#M342931</link>
    <description>&lt;P&gt;No macro needed, just an array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let nobs=100;
data want;
    array x_ {&amp;amp;nobs};
    do i=1 to dim(x_);
         x_(i)=rand('normal');
    end;
    output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, I notice in the code you provided, that it produces one observation with 100 variables. Is that really what you want?&lt;/P&gt;</description>
    <pubDate>Wed, 05 Apr 2023 10:55:24 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-04-05T10:55:24Z</dc:date>
    <item>
      <title>Macro to create number of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-create-number-of-variables/m-p/868179#M342929</link>
      <description>&lt;P&gt;Hello SAS community&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am running the code below to create new variables in a data set:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let NObs = 100;&lt;BR /&gt;data t;&lt;BR /&gt;do i = 1 to &amp;amp;NObs;&lt;BR /&gt;x_1 = rand("Normal");&amp;nbsp;&lt;BR /&gt;x_2 = rand("Normal");&amp;nbsp;&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;x_n = rand("Normal");&amp;nbsp;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to form a macro to control how many variables to create, i.e., the value of N.&lt;/P&gt;
&lt;P&gt;For example, if N=10 I need 10 variables, up to X_10. I need to be able to change N to different values, as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Costas&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, 05 Apr 2023 10:44:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-create-number-of-variables/m-p/868179#M342929</guid>
      <dc:creator>costasRO</dc:creator>
      <dc:date>2023-04-05T10:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to create number of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-create-number-of-variables/m-p/868183#M342931</link>
      <description>&lt;P&gt;No macro needed, just an array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let nobs=100;
data want;
    array x_ {&amp;amp;nobs};
    do i=1 to dim(x_);
         x_(i)=rand('normal');
    end;
    output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, I notice in the code you provided, that it produces one observation with 100 variables. Is that really what you want?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2023 10:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-create-number-of-variables/m-p/868183#M342931</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-05T10:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to create number of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-create-number-of-variables/m-p/868196#M342937</link>
      <description>&lt;P&gt;Thank you for this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No, I want each of the N variables to have 100 observations, drawn from the specified distribution.&lt;/P&gt;
&lt;P&gt;.In fact the code I was using is below, and I would like&amp;nbsp; a more flexible way to determine the number of x's (7 in my code below). Thank you again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let NObs = 100;&lt;BR /&gt;data t;&lt;BR /&gt;do i = 1 to &amp;amp;NObs;&lt;BR /&gt;x1 = rand("Normal");&amp;nbsp;&lt;BR /&gt;x2 = rand("Normal");&amp;nbsp;&lt;BR /&gt;x3 = rand("Normal");&amp;nbsp;&lt;BR /&gt;x4 = rand("Normal");&amp;nbsp;&lt;BR /&gt;x5 = rand("Normal");&amp;nbsp;&lt;BR /&gt;x6 = rand("Normal");&amp;nbsp;&lt;BR /&gt;x7 = rand("Normal");&amp;nbsp;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2023 11:25:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-create-number-of-variables/m-p/868196#M342937</guid>
      <dc:creator>costasRO</dc:creator>
      <dc:date>2023-04-05T11:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to create number of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-create-number-of-variables/m-p/868197#M342938</link>
      <description>&lt;P&gt;Still no macro needed&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let nobs=100;
%let nvars=7;
data want;
    array x_ {&amp;amp;nvars};
    do j=1 to &amp;amp;nobs;
        do i=1 to dim(x_);
             x_(i)=rand('normal');
        end;
        output;
    end;
    drop i j;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Apr 2023 11:57:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-create-number-of-variables/m-p/868197#M342938</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-05T11:57:44Z</dc:date>
    </item>
  </channel>
</rss>

