<?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 to define numeric array using character variables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-define-numeric-array-using-character-variables/m-p/745505#M233694</link>
    <description>&lt;P&gt;Hi &lt;A class="trigger-hovercard" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381766" target="_blank"&gt;ShashankB1987&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;You can do it using the following solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sales2 (keep=prod Jan_Total_sales Feb_Total_sales Mar_Total_sales);
   set sales;
   array units[3] Jan_Units Feb_Units Mar_Units;
   array price[3] Jan_Price Feb_Price Mar_Price;
   array total[3] Jan_Total_sales Feb_Total_sales Mar_Total_sales;
   do i=1 to dim(units);
      total[i] = units[i] * price{i];
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
    <pubDate>Thu, 03 Jun 2021 15:27:20 GMT</pubDate>
    <dc:creator>LeonidBatkhan</dc:creator>
    <dc:date>2021-06-03T15:27:20Z</dc:date>
    <item>
      <title>How to define numeric array using character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-define-numeric-array-using-character-variables/m-p/745493#M233686</link>
      <description>&lt;P&gt;data sales;&lt;BR /&gt;input prod $ Jan_Units Feb_Units Mar_Units Jan_Price Feb_Price Mar_Price ;&lt;BR /&gt;cards;&lt;BR /&gt;A 408 323 168 10 10 12&lt;BR /&gt;B 632 631 100 15 10 14&lt;BR /&gt;C 619 677 285 14 15 11&lt;BR /&gt;D 846 136 831 15 13 13&lt;BR /&gt;E 518 440 630 12 11 13&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;Output Needs to be:&lt;/P&gt;&lt;P&gt;Product Jan_Total_sales Feb_Total_sales Mar_Total_sales&lt;BR /&gt;A 4080 3230 2016&lt;BR /&gt;B 9480 6310 1400&lt;BR /&gt;C 8666 10155 3135&lt;BR /&gt;D 12690 1768 10803&lt;BR /&gt;E 6216 4840 8190&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;When I run the below code,&lt;/P&gt;&lt;P&gt;data sales2;&lt;BR /&gt;set sales;&lt;BR /&gt;array Units[3] Jan_Units-Jun_Units;&lt;BR /&gt;array Price[3] Jan_Price-Jun_Price;&lt;BR /&gt;array Total_Sales[3];&lt;BR /&gt;do i=1 to 3;&lt;BR /&gt;Total_Sales[i] = Units[i]*Price[i];&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I get the below error;&lt;/P&gt;&lt;P&gt;ERROR: Missing numeric suffix on a numbered variable list (Jan_Units-Mar_Units).&lt;BR /&gt;ERROR: Too few variables defined for the dimension(s) specified for the array Units.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please advice me in the above mentioned error?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 15:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-define-numeric-array-using-character-variables/m-p/745493#M233686</guid>
      <dc:creator>ShashankB1987</dc:creator>
      <dc:date>2021-06-03T15:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to define numeric array using character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-define-numeric-array-using-character-variables/m-p/745497#M233689</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381766"&gt;@ShashankB1987&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use &lt;A href="https://documentation.sas.com/doc/en/lrcon/9.4/p0wphcpsfgx6o7n1sjtqzizp1n39.htm#p1cr0027z6qx4an1maoh0fyizqtt" target="_blank" rel="noopener"&gt;name range lists&lt;/A&gt;&amp;nbsp;(with a double dash) in the array definitions:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array Units[*] Jan_Units--Mar_Units;
array Price[*] Jan_Price--Mar_Price;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(Leave it to SAS to determine the array dimension, based on the number of variables in the list, i.e., specify "&lt;FONT face="courier new,courier"&gt;[*]&lt;/FONT&gt;". Then you don't have to adjust it when you switch from March to June. Make sure, however, that &lt;FONT face="courier new,courier"&gt;Jan_Units&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;Feb_Units&lt;/FONT&gt; etc. appear in chronological order in the input dataset and also not mixed with &lt;FONT face="courier new,courier"&gt;Jan_Price&lt;/FONT&gt;, etc.)&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 15:26:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-define-numeric-array-using-character-variables/m-p/745497#M233689</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-06-03T15:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to define numeric array using character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-define-numeric-array-using-character-variables/m-p/745502#M233693</link>
      <description>&lt;P&gt;Because you have variable names that do not have a natural integer based sequence you cannot use the Var1-varn type list. That form expects sequentially&amp;nbsp; numbered variable names with the same base.&lt;/P&gt;
&lt;P&gt;If the columns are adjacent in the data then you can use the two dash list:&amp;nbsp;&amp;nbsp; Jan_Units -- Jun_Units; but this will work only if 1) the columns are sequential in the data set, i.e. Proc Contents reports the column numbers in sequence and 2) The variables already exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second thing: In this line of code:&lt;/P&gt;
&lt;P&gt;array Units[3] Jan_Units-Jun_Units;&lt;/P&gt;
&lt;P&gt;Your data does not show any variable named &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;Jun_units&lt;/STRONG&gt;&lt;/FONT&gt; and if intended to use Jan, Feb, Mar, Apr, May AND Jun then why would you stick the 3 in the Units definition?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Or just spell out all the names and skip lists.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are placing data in variable names, Jan, Feb, Mar etc. This often indicates poor data structures and spreadsheet thinking which will add complexity to coding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you actually had provided a valid list and the number of elements does not match the array definition then you have another cause of errors. Example:&lt;/P&gt;
&lt;PRE&gt;data junk;
  input x1 - x6;
datalines;
1 2 3 4 5 6
;

data want;
   set junk;
   array units[3] x1-x6;
run;&lt;/PRE&gt;
&lt;P&gt;Will generate:&lt;/P&gt;
&lt;PRE&gt;13   data want;
14      set junk;
15      array units[3] x1-x6;
ERROR: Too many variables defined for the dimension(s) specified for the array units.
16   run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.WANT may be incomplete.  When this step was stopped there were 0
         observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 15:23:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-define-numeric-array-using-character-variables/m-p/745502#M233693</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-03T15:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to define numeric array using character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-define-numeric-array-using-character-variables/m-p/745505#M233694</link>
      <description>&lt;P&gt;Hi &lt;A class="trigger-hovercard" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381766" target="_blank"&gt;ShashankB1987&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;You can do it using the following solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sales2 (keep=prod Jan_Total_sales Feb_Total_sales Mar_Total_sales);
   set sales;
   array units[3] Jan_Units Feb_Units Mar_Units;
   array price[3] Jan_Price Feb_Price Mar_Price;
   array total[3] Jan_Total_sales Feb_Total_sales Mar_Total_sales;
   do i=1 to dim(units);
      total[i] = units[i] * price{i];
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 15:27:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-define-numeric-array-using-character-variables/m-p/745505#M233694</guid>
      <dc:creator>LeonidBatkhan</dc:creator>
      <dc:date>2021-06-03T15:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to define numeric array using character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-define-numeric-array-using-character-variables/m-p/745508#M233696</link>
      <description>&lt;P&gt;Your primary problem is bad data design.&lt;/P&gt;
&lt;P&gt;From a dataset containing these variables&lt;/P&gt;
&lt;PRE&gt;product month units price&lt;/PRE&gt;
&lt;P&gt;it is a simple multiplication, and a wide report can easily be done by using month as ACROSS in PROC REPORT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maxim 19: Long Beats Wide.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 15:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-define-numeric-array-using-character-variables/m-p/745508#M233696</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-03T15:29:13Z</dc:date>
    </item>
  </channel>
</rss>

