<?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: Issue with arrays for creating new variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-arrays-for-creating-new-variables/m-p/364369#M275043</link>
    <description>&lt;P&gt;Get rid of the OUTPUT statement to get rid of the extra observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, you may be creating your new variables as numeric instead of character.&amp;nbsp; If the new variables are not already defined earlier in your program, change the array statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array x[12] $ 1 month1-month12;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Jun 2017 20:43:36 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-06-05T20:43:36Z</dc:date>
    <item>
      <title>Issue with arrays for creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-arrays-for-creating-new-variables/m-p/364365#M275041</link>
      <description>&lt;P&gt;I have a 12-characters variable sales in the form of, say, "YYYNNNYNYYYN". I am using array to create 12 new variables with one character each. When I use array with substring, I am getting not only 12 variables but also 12 new rows for each observation. So, if I had 50 observations, I am now getting 12*50=600 observations, along with the 12 newly created variables. I am not able to figure out why this is happening.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The syntax I am using is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;array x[12] month1-month12;&lt;/P&gt;&lt;P&gt;do i=1 to 12;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;x[i]=substr(sales, i, 1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;output;&lt;/P&gt;&lt;P&gt;end;&amp;nbsp;&lt;/P&gt;&lt;P&gt;drop i;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jun 2017 20:29:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-arrays-for-creating-new-variables/m-p/364365#M275041</guid>
      <dc:creator>Mahip</dc:creator>
      <dc:date>2017-06-05T20:29:14Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with arrays for creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-arrays-for-creating-new-variables/m-p/364368#M275042</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array x[12] month1-month12;
do i=1 to 12;
     x[i]=substr(sales, i, 1);
     output;
end; 
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;OUTPUT is within the loop. Move it to outside of the loop, so it outputs at the END of the process. Now it outputs every record*month so you get N*12 records in total. FYI- you can use the CHAR or Substr() to loop this, I find the CHAR function more useful.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another option - if you read this file from a CSV or other dataset you may be able to modify the input to read all the records initially.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jun 2017 20:43:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-arrays-for-creating-new-variables/m-p/364368#M275042</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-05T20:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with arrays for creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-arrays-for-creating-new-variables/m-p/364369#M275043</link>
      <description>&lt;P&gt;Get rid of the OUTPUT statement to get rid of the extra observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, you may be creating your new variables as numeric instead of character.&amp;nbsp; If the new variables are not already defined earlier in your program, change the array statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array x[12] $ 1 month1-month12;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jun 2017 20:43:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-arrays-for-creating-new-variables/m-p/364369#M275043</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-05T20:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with arrays for creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-arrays-for-creating-new-variables/m-p/364610#M275044</link>
      <description>&lt;P&gt;Ok, this is just for fun :),&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
sales='YYYNNNYNYYYN';
array x[12] $ 1 month1-month12;
call pokelong(sales,addrlong(x(1)),dim(x));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Jun 2017 14:59:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-arrays-for-creating-new-variables/m-p/364610#M275044</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2017-06-06T14:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with arrays for creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-arrays-for-creating-new-variables/m-p/365044#M275045</link>
      <description>Reads like P. Dorfman code &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 07 Jun 2017 15:34:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-arrays-for-creating-new-variables/m-p/365044#M275045</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-06-07T15:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with arrays for creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-arrays-for-creating-new-variables/m-p/365049#M275046</link>
      <description>&lt;P&gt;Indeed!&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2017 15:37:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-arrays-for-creating-new-variables/m-p/365049#M275046</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2017-06-07T15:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with arrays for creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-arrays-for-creating-new-variables/m-p/365432#M275047</link>
      <description>&lt;P&gt;Thank you everyone for your comments! They were very helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2017 16:06:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-arrays-for-creating-new-variables/m-p/365432#M275047</guid>
      <dc:creator>Mahip</dc:creator>
      <dc:date>2017-06-08T16:06:41Z</dc:date>
    </item>
  </channel>
</rss>

