<?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: sum up all fields start with &amp;quot;x&amp;quot; in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sum-up-all-fields-start-with-quot-x-quot/m-p/582118#M165515</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to sum up all variables start with "x"&lt;/P&gt;
&lt;P&gt;Way1 to do it&amp;nbsp; is:&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;x_sum1=sum(x1901,x1902,x1903,x1904,x1905,x1906);&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Since in real I have many fields then I want to find a more clever way to do it&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Why is it not working?&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;x_sum2=sum(x:);&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;_&lt;BR /&gt;388&lt;BR /&gt;200&lt;BR /&gt;76&lt;BR /&gt;ERROR 388-185: Expecting an arithmetic operator.&lt;/P&gt;
&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input x1901 x1902 x1903 x1904 x1905 x1906;
cards;
10 20 30 40 50 60
;
run;

data b;
set a;
x_sum1=sum(x1901,x1902,x1903,x1904,x1905,x1906);
x_sum2=sum(x:);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Reiterate: Paste LOG into a code box as well.&lt;/P&gt;
&lt;P&gt;When you use a list indicator like X: then you need the key word "of" as in sum(of x: ) ; Otherwise the compiler doesn't know what you want to do. Similar with an array as the argument. Error: z= sum ( y(*) );&amp;nbsp; Correct: z= sum (of y(*)); (Assumes y is a correctly defined array)&lt;/P&gt;
&lt;P&gt;BTW if you use&lt;/P&gt;
&lt;PRE&gt;x_sum1=sum(x1901,x1902,x1903,x1904,x1905,x1906);
x_sum2=sum( of x:);
&lt;/PRE&gt;
&lt;P&gt;then x_sum2 will be equivalent to sum(&lt;STRONG&gt;x_sum1&lt;/STRONG&gt;,x1901&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;x1902&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;x1903&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;x1904&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;x1905&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;x1906&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;; assuming that x1901 - x1906 were all of the other X variables. So you may want to be careful with the order of your code and variable name lists.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 19 Aug 2019 14:52:22 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-08-19T14:52:22Z</dc:date>
    <item>
      <title>sum up all fields start with "x"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-up-all-fields-start-with-quot-x-quot/m-p/582044#M165489</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to sum up all variables start with "x"&lt;/P&gt;
&lt;P&gt;Way1 to do it&amp;nbsp; is:&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;x_sum1=sum(x1901,x1902,x1903,x1904,x1905,x1906);&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Since in real I have many fields then I want to find a more clever way to do it&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Why is it not working?&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;x_sum2=sum(x:);&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;_&lt;BR /&gt;388&lt;BR /&gt;200&lt;BR /&gt;76&lt;BR /&gt;ERROR 388-185: Expecting an arithmetic operator.&lt;/P&gt;
&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input x1901 x1902 x1903 x1904 x1905 x1906;
cards;
10 20 30 40 50 60
;
run;

data b;
set a;
x_sum1=sum(x1901,x1902,x1903,x1904,x1905,x1906);
x_sum2=sum(x:);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Aug 2019 05:30:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-up-all-fields-start-with-quot-x-quot/m-p/582044#M165489</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-08-19T05:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: sum up all fields start with "x"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-up-all-fields-start-with-quot-x-quot/m-p/582045#M165490</link>
      <description>&lt;P&gt;I found the solution.&lt;/P&gt;
&lt;P&gt;Is there another way to do it?&lt;/P&gt;
&lt;P&gt;Maybe with arrays?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
set a;
sum1=sum(x1901,x1902,x1903,x1904,x1905,x1906);
sum2=sum(of  x:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2019 05:33:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-up-all-fields-start-with-quot-x-quot/m-p/582045#M165490</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-08-19T05:33:08Z</dc:date>
    </item>
    <item>
      <title>Re: sum up all fields start with "x"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-up-all-fields-start-with-quot-x-quot/m-p/582047#M165492</link>
      <description>&lt;P&gt;Why do you think that using arrays will allow an easier solution? I don't know a solution with less code than &lt;/P&gt;
&lt;PRE&gt;sum2=sum(of x:);&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Aug 2019 06:08:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-up-all-fields-start-with-quot-x-quot/m-p/582047#M165492</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-08-19T06:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: sum up all fields start with "x"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-up-all-fields-start-with-quot-x-quot/m-p/582109#M165512</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I found the solution.&lt;/P&gt;
&lt;P&gt;Is there another way to do it?&lt;/P&gt;
&lt;P&gt;Maybe with arrays?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
set a;
sum1=sum(x1901,x1902,x1903,x1904,x1905,x1906);
sum2=sum(of  x:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you already have the array defined then you can use the array name with * for the index.&amp;nbsp; So if you defined the array using the name Xarray the syntax would look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sum3=sum(of  Xarray[*]);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Aug 2019 14:02:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-up-all-fields-start-with-quot-x-quot/m-p/582109#M165512</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-19T14:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: sum up all fields start with "x"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-up-all-fields-start-with-quot-x-quot/m-p/582118#M165515</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to sum up all variables start with "x"&lt;/P&gt;
&lt;P&gt;Way1 to do it&amp;nbsp; is:&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;x_sum1=sum(x1901,x1902,x1903,x1904,x1905,x1906);&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Since in real I have many fields then I want to find a more clever way to do it&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Why is it not working?&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;x_sum2=sum(x:);&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;_&lt;BR /&gt;388&lt;BR /&gt;200&lt;BR /&gt;76&lt;BR /&gt;ERROR 388-185: Expecting an arithmetic operator.&lt;/P&gt;
&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input x1901 x1902 x1903 x1904 x1905 x1906;
cards;
10 20 30 40 50 60
;
run;

data b;
set a;
x_sum1=sum(x1901,x1902,x1903,x1904,x1905,x1906);
x_sum2=sum(x:);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Reiterate: Paste LOG into a code box as well.&lt;/P&gt;
&lt;P&gt;When you use a list indicator like X: then you need the key word "of" as in sum(of x: ) ; Otherwise the compiler doesn't know what you want to do. Similar with an array as the argument. Error: z= sum ( y(*) );&amp;nbsp; Correct: z= sum (of y(*)); (Assumes y is a correctly defined array)&lt;/P&gt;
&lt;P&gt;BTW if you use&lt;/P&gt;
&lt;PRE&gt;x_sum1=sum(x1901,x1902,x1903,x1904,x1905,x1906);
x_sum2=sum( of x:);
&lt;/PRE&gt;
&lt;P&gt;then x_sum2 will be equivalent to sum(&lt;STRONG&gt;x_sum1&lt;/STRONG&gt;,x1901&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;x1902&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;x1903&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;x1904&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;x1905&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;x1906&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;; assuming that x1901 - x1906 were all of the other X variables. So you may want to be careful with the order of your code and variable name lists.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2019 14:52:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-up-all-fields-start-with-quot-x-quot/m-p/582118#M165515</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-19T14:52:22Z</dc:date>
    </item>
  </channel>
</rss>

