<?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 proc sql create band and sum variable help in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-create-band-and-sum-variable-help/m-p/851407#M336520</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Banded_1 as
   select sc.score_band
            ,count(*) as Volume
            ,sum(sc.Projected12) as Projected
     from ac_banded as sc
     group by sc.score_band
     order by sc.score_band;
quit;

data Banded_2;
   set Banded_1;
   if score_band in ('le550','le560) then score_band_new='le560';
       else score_band_new=score_band;
run;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;         &lt;BR /&gt;proc&amp;nbsp;sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;create&amp;nbsp;table&amp;nbsp;Banded_3&amp;nbsp;as&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;select&amp;nbsp;score_band&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;,sum(Volume)&amp;nbsp;as&amp;nbsp;Volume&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;,Projected&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;from&amp;nbsp;Banded_2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;group&amp;nbsp;by&amp;nbsp;score_band;&lt;BR /&gt;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hi, I've used the code above to try and calculate the overall 'Projected' figure for each score_band but when I try to combine the 'le550' and 'le560' score bands into one ('le560'), the summed 'Projected' figure in my 'Banded_3' output is incorrect as it gives me two 'le560' rows instead of just the one (as you can see with my screenshot below). Can someone help me to adjust my code to get my desired outcome, as shown below in the screenshot? Thanks in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Justin9_0-1672262571666.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78909i8C4A4EB0DD21391C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Justin9_0-1672262571666.png" alt="Justin9_0-1672262571666.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 28 Dec 2022 23:54:10 GMT</pubDate>
    <dc:creator>Justin9</dc:creator>
    <dc:date>2022-12-28T23:54:10Z</dc:date>
    <item>
      <title>proc sql create band and sum variable help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-create-band-and-sum-variable-help/m-p/851407#M336520</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Banded_1 as
   select sc.score_band
            ,count(*) as Volume
            ,sum(sc.Projected12) as Projected
     from ac_banded as sc
     group by sc.score_band
     order by sc.score_band;
quit;

data Banded_2;
   set Banded_1;
   if score_band in ('le550','le560) then score_band_new='le560';
       else score_band_new=score_band;
run;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;         &lt;BR /&gt;proc&amp;nbsp;sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;create&amp;nbsp;table&amp;nbsp;Banded_3&amp;nbsp;as&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;select&amp;nbsp;score_band&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;,sum(Volume)&amp;nbsp;as&amp;nbsp;Volume&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;,Projected&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;from&amp;nbsp;Banded_2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;group&amp;nbsp;by&amp;nbsp;score_band;&lt;BR /&gt;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hi, I've used the code above to try and calculate the overall 'Projected' figure for each score_band but when I try to combine the 'le550' and 'le560' score bands into one ('le560'), the summed 'Projected' figure in my 'Banded_3' output is incorrect as it gives me two 'le560' rows instead of just the one (as you can see with my screenshot below). Can someone help me to adjust my code to get my desired outcome, as shown below in the screenshot? Thanks in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Justin9_0-1672262571666.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78909i8C4A4EB0DD21391C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Justin9_0-1672262571666.png" alt="Justin9_0-1672262571666.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2022 23:54:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-create-band-and-sum-variable-help/m-p/851407#M336520</guid>
      <dc:creator>Justin9</dc:creator>
      <dc:date>2022-12-28T23:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql create band and sum variable help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-create-band-and-sum-variable-help/m-p/851425#M336529</link>
      <description>&lt;P&gt;Should be done in a single step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Banded as
   select 
		case when score_band="le550" then "le560" 
		else score_band end as score_band_new,
        count(*) as Volume,
        sum(Projected12) as Projected
     from ac_banded
     group by calculated score_band_new;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2022 22:30:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-create-band-and-sum-variable-help/m-p/851425#M336529</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-12-28T22:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql create band and sum variable help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-create-band-and-sum-variable-help/m-p/851435#M336535</link>
      <description>&lt;P&gt;Thanks for the reply. It's still not giving me the intended outcome that I had in the screenshot, so can someone suggest another method that I could use to edit the proc sql of the 'Banded_3' section of code? Ideally, I'd keep the first two sections of code as they are (though I did add in an extra line of code in 'Banded_1 with &lt;CODE class=" language-sas"&gt;,sum(sc.Projected12) as Projected&lt;/CODE&gt;), as it was developed that way and I'm only trying to create 'Banded_3' to find out the sum of the 'Projected_12' for each of the score bands&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2022 23:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-create-band-and-sum-variable-help/m-p/851435#M336535</guid>
      <dc:creator>Justin9</dc:creator>
      <dc:date>2022-12-28T23:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql create band and sum variable help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-create-band-and-sum-variable-help/m-p/851443#M336539</link>
      <description>If anyone has any ideas to change my added line in 'Banded_1' and the whole 'Banded_3' section (which is what I've created), please can you help me with the necessary code to get the screenshot please!</description>
      <pubDate>Thu, 29 Dec 2022 00:20:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-create-band-and-sum-variable-help/m-p/851443#M336539</guid>
      <dc:creator>Justin9</dc:creator>
      <dc:date>2022-12-29T00:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql create band and sum variable help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-create-band-and-sum-variable-help/m-p/851453#M336541</link>
      <description>&lt;P&gt;If you're after some actual code that's tested then please provide suitable sample data in the form of a SAS data step that creates such data. Also show the desired result based on that sample data and explain the logic required to transform the source to the desired target state.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Dec 2022 01:37:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-create-band-and-sum-variable-help/m-p/851453#M336541</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-12-29T01:37:51Z</dc:date>
    </item>
  </channel>
</rss>

