<?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: Case Statement with Multiple values in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Case-Statement-with-Multiple-values/m-p/730481#M28400</link>
    <description>&lt;P&gt;Candidate for some repeated redundant inefficient code:&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;when month(A.Month_End) = 11 and month(A.Month_End) IN (10,11)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you have multiple statements where you have equality then membership of that same value in a list. 11 is ALWAYS in (10 11) so the second part of all of those is not needed unless you really want to type unneeded stuff.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't show us a definition for your &amp;amp;fy_prev macro variable but this looks somewhat suspect:&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;SUM(when month(A.Month_End) = 1 and month(A.Month_End) IN (10,11,12,1) and Year(A.Month_End) = &amp;amp;fy_prev.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because the year value very likely to be different than for the Oct, Nov and Dec data&lt;/P&gt;</description>
    <pubDate>Wed, 31 Mar 2021 19:49:45 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-03-31T19:49:45Z</dc:date>
    <item>
      <title>Case Statement with Multiple values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Case-Statement-with-Multiple-values/m-p/730287#M28393</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;

select distinct  
			month(A.Month_End),
			A.Month_End,
			A.RTAM_ID,
			Year(A.Month_End),
			&amp;amp;fyear.,
			&amp;amp;fy_prev.,
			SUM(case when product=66 then value else 0 end) as MTRC_DOL_VAL1, /*cl_Promoters*/
          SUM(case when product=67 then value else 0 end) as MTRC_DOL_VAL2, /*cl_Detractors*/
          SUM(case when product=25 then value else 0 end) as MTRC_DOL_VAL3, /*cl_Responses*/
		sum((case when month(A.Month_End) = 10 and Year(A.Month_End) = &amp;amp;fy_prev. and product=25 then A.Value)
			sum(when month(A.Month_End) = 11 and month(A.Month_End) IN (10,11) and Year(A.Month_End) = &amp;amp;fy_prev. and product=25 then A.Value)
			SUM(when month(A.Month_End) = 12 and month(A.Month_End) IN (10,11,12) and Year(A.Month_End) = &amp;amp;fy_prev. and product=25 then A.Value)
			SUM(when month(A.Month_End) = 1 and month(A.Month_End) IN (10,11,12,1) and Year(A.Month_End) = &amp;amp;fy_prev. and product=25 then A.Value)

else 0 end) as MTR1
from 

  	(SELECT distinct 
			t1.date,
			input(t1.date, yymmdd10.) format date9. as Month_End,
		  t1.transit				as Transit,
          (t1.transit*1000) + t1.am as RTAM_ID,
		  2000						as MTRC_ID,
		  'NPS'						as MTRC_NM,
			. as Month_IN_YEAR,
		 	. as fiscal_mth_of_year,
			. as mth_num,
			t1.value,
			t1.product
	FROM  nps.nps_master_&amp;amp;descdt. as t1
	
	where    t1.product in (25,66,67)) as A 
	Group by 1,2,3

	order by A.Month_End
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hi, I am new to SAS and trying to solve the issue of running totals between multiple years.&lt;/P&gt;&lt;P&gt;For example,&lt;/P&gt;&lt;P&gt;if the Month 11 value is 2&lt;/P&gt;&lt;P&gt;and Month 12 value 2 I want to sum in the Month 12 value = 4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 02:01:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Case-Statement-with-Multiple-values/m-p/730287#M28393</guid>
      <dc:creator>Jwaryah</dc:creator>
      <dc:date>2021-03-31T02:01:56Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement with Multiple values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Case-Statement-with-Multiple-values/m-p/730296#M28394</link>
      <description>&lt;P&gt;What does your input data look like? What is it that you want out?&lt;/P&gt;
&lt;P&gt;Why are you writing SQL code instead of just normal SAS code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you trying to generate a running sum?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have ;
  running_sum + value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Something else?&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 04:03:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Case-Statement-with-Multiple-values/m-p/730296#M28394</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-31T04:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement with Multiple values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Case-Statement-with-Multiple-values/m-p/730385#M28398</link>
      <description>&lt;P&gt;Thanks for the response. Please see the attached dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I said i am new to SAS that was the reason using SQL code&lt;/P&gt;&lt;P&gt;But i can try to use the SAS instead using SQL.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 12:51:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Case-Statement-with-Multiple-values/m-p/730385#M28398</guid>
      <dc:creator>Jwaryah</dc:creator>
      <dc:date>2021-03-31T12:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement with Multiple values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Case-Statement-with-Multiple-values/m-p/730391#M28399</link>
      <description>&lt;P&gt;So first step is to post example data in a way that other can use it to help understand the problem and make it easy for them to provide you code.&lt;/P&gt;
&lt;P&gt;Looks like you have this data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data nps_tech ;
  input Month_End :date. Transit RTAM_ID MTRC_ID MTRC_NM :$3.
        Month_IN_YEAR fiscal_mth_of_year mth_num 
        MTRC_DOL_VAL1 MTRC_DOL_VAL2 MTRC_DOL_VAL3
  ;
  format Month_End date9. ;
datalines4;
28FEB2021  1386  1386704 2000 NPS . . . 1 1 2
28FEB2021  1386  1386721 2000 NPS . . . 1 1 2
28FEB2021  1386  1386829 2000 NPS . . . 0 0 1
28FEB2021  7215  7215455 2000 NPS . . . 2 0 2
28FEB2021 10054 10054072 2000 NPS . . . 1 0 2
28FEB2021 13820 13820245 2000 NPS . . . 0 1 1
28FEB2021 13820 13820378 2000 NPS . . . 1 0 1
28FEB2021 14455 14455608 2000 NPS . . . 0 1 1
28FEB2021 14456 14456450 2000 NPS . . . 0 1 1
28FEB2021 17262 17262057 2000 NPS . . . 1 0 1
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You also need to provide more explanation of what these variable are, especially since none of them have any descriptive labels attached.&lt;/P&gt;
&lt;P&gt;Now describe what is it that you are trying to generate from this data?&amp;nbsp; First describe in words what you are trying to create.&amp;nbsp; Then provide the results that could be produced from this input data, preferable in a similar simple SAS data step format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can show any code you tried to use and explain how it failed to produce the results you wanted.&amp;nbsp; Did it run with errors? If so show the SAS log so the errors can be seen in context of the code run.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 13:32:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Case-Statement-with-Multiple-values/m-p/730391#M28399</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-31T13:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement with Multiple values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Case-Statement-with-Multiple-values/m-p/730481#M28400</link>
      <description>&lt;P&gt;Candidate for some repeated redundant inefficient code:&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;when month(A.Month_End) = 11 and month(A.Month_End) IN (10,11)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you have multiple statements where you have equality then membership of that same value in a list. 11 is ALWAYS in (10 11) so the second part of all of those is not needed unless you really want to type unneeded stuff.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't show us a definition for your &amp;amp;fy_prev macro variable but this looks somewhat suspect:&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;SUM(when month(A.Month_End) = 1 and month(A.Month_End) IN (10,11,12,1) and Year(A.Month_End) = &amp;amp;fy_prev.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because the year value very likely to be different than for the Oct, Nov and Dec data&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 19:49:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Case-Statement-with-Multiple-values/m-p/730481#M28400</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-31T19:49:45Z</dc:date>
    </item>
  </channel>
</rss>

