<?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: Summation of observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-observations/m-p/489485#M127822</link>
    <description>&lt;P&gt;use substr(bike,1,2)='Ax'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Demo:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bike;
input bike $ sales;
datalines;
A       1
A       4
B       4
B       4
Ax01   5
Ax03   5
Ax04   5
;

proc sql;
create table want as
select  ifC(upcase(substr(bike,1,2))='AX','AX','REST') as brand,sum(sales) as sum_sales
from bike
group by brand;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 24 Aug 2018 03:58:52 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-08-24T03:58:52Z</dc:date>
    <item>
      <title>Summation of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-observations/m-p/489476#M127815</link>
      <description>&lt;P&gt;Am trying to summarize data based on a condition. I would like to summarize some of the bikes together and the rest together.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The sample data is as below -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data bike;&lt;BR /&gt;input bike $ sales;&lt;BR /&gt;datalines;&lt;BR /&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;BR /&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;BR /&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;BR /&gt;C01&amp;nbsp; &amp;nbsp;5&lt;BR /&gt;C03&amp;nbsp; &amp;nbsp;5&lt;BR /&gt;C04&amp;nbsp; &amp;nbsp;5&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;Output desired - summation of sales of all C bikes and summation of rest of the bikes(A+B).&amp;nbsp; ie. "C" = (C01+C02+C03) and "rest" = (A+B)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;bike sales&lt;BR /&gt;C 15&lt;BR /&gt;rest 13&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Feel that the desired output can come from a union of two tables, one for all&amp;nbsp;the C bikes and other for the rest of the bikes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table Bi as&lt;BR /&gt;select *&lt;BR /&gt;from DATA&lt;BR /&gt;where&amp;nbsp;bike&amp;nbsp;^contains "C"&lt;BR /&gt;union all&lt;BR /&gt;select bike as "rest",&lt;BR /&gt;sum(sales) as sales&lt;BR /&gt;from (select * from DATA&amp;nbsp;where bike contains "C" )&lt;BR /&gt;group by bike;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Looking for some guidance.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Aug 2018 02:24:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-observations/m-p/489476#M127815</guid>
      <dc:creator>75063</dc:creator>
      <dc:date>2018-08-24T02:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: Summation of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-observations/m-p/489480#M127818</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bike;
input bike $ sales;
datalines;
A       1
A       4
B       4
B       4
C01   5
C03   5
C04   5
;

proc sql;
create table want as
select  ifC(first(bike)='C','C','REST') as brand,sum(sales) as sum_sales
from bike
group by brand;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Aug 2018 02:44:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-observations/m-p/489480#M127818</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-24T02:44:17Z</dc:date>
    </item>
    <item>
      <title>Re: Summation of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-observations/m-p/489484#M127821</link>
      <description>&lt;P&gt;Thank you for your reply.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can see that the ifc(FIRST(&amp;nbsp; ) function takes the first character in a character string,&amp;nbsp; What if i want to choose the first two characters of the character string.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example if my data would have been&amp;nbsp; -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; bike&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; bike &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt; sales&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;datalines&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;A       1
A       4
B       4
B       4
Ax01   5
Ax03   5
Ax04   5&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;then if I had to sum up all the data with Ax (Ax01+Ax02+Ax03)&amp;nbsp; and sum up the rest (A+B) with the desired output -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;brand&amp;nbsp; sales&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rest&amp;nbsp; &amp;nbsp; &amp;nbsp; 13&lt;/P&gt;&lt;P&gt;Ax&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;15&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;</description>
      <pubDate>Fri, 24 Aug 2018 03:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-observations/m-p/489484#M127821</guid>
      <dc:creator>75063</dc:creator>
      <dc:date>2018-08-24T03:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Summation of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-observations/m-p/489485#M127822</link>
      <description>&lt;P&gt;use substr(bike,1,2)='Ax'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Demo:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bike;
input bike $ sales;
datalines;
A       1
A       4
B       4
B       4
Ax01   5
Ax03   5
Ax04   5
;

proc sql;
create table want as
select  ifC(upcase(substr(bike,1,2))='AX','AX','REST') as brand,sum(sales) as sum_sales
from bike
group by brand;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Aug 2018 03:58:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-observations/m-p/489485#M127822</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-24T03:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Summation of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-observations/m-p/489491#M127826</link>
      <description>&lt;P&gt;As soon as you have more different groups proc sql gets unnecessary confusing. Why not using a format?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
   value $bikeGroups 
      'C01', 'C03', 'C04' = 'C'
      other = 'rest'
   ;
run;

proc summary data=bike nway;
   class bike / order=formatted;
   format bike $bikeGroups.;
   var sales;
   output out=work.want(drop=_type_ _freq_) sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Aug 2018 04:45:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-observations/m-p/489491#M127826</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-08-24T04:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: Summation of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-observations/m-p/489497#M127829</link>
      <description>Thank you for your response and guidance.</description>
      <pubDate>Fri, 24 Aug 2018 06:21:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-observations/m-p/489497#M127829</guid>
      <dc:creator>75063</dc:creator>
      <dc:date>2018-08-24T06:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Summation of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-observations/m-p/489498#M127830</link>
      <description>Awesome &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thank you for the guidance.</description>
      <pubDate>Fri, 24 Aug 2018 06:22:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-observations/m-p/489498#M127830</guid>
      <dc:creator>75063</dc:creator>
      <dc:date>2018-08-24T06:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: Summation of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-observations/m-p/489499#M127831</link>
      <description>This worked very well for my problem &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thank you !</description>
      <pubDate>Fri, 24 Aug 2018 06:23:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-observations/m-p/489499#M127831</guid>
      <dc:creator>75063</dc:creator>
      <dc:date>2018-08-24T06:23:53Z</dc:date>
    </item>
  </channel>
</rss>

