<?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: sume observations on the base of variable content in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sume-observations-on-the-base-of-variable-content/m-p/279949#M56498</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if you need it one time you can hard code it&amp;nbsp; as in my example otherwise you shall write a macro .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd;
input abc2016 bcd2015 a2015b cd2016;
datalines;
10, 5, 2, 3
;
run;

proc sql noprint;
select name into :vr2015 separated by ' ' from
sashelp.vcolumn
where libname="WORK" and memname="HAVE" 
and name contains '2015';
select name into :vr2016 separated by ' ' from
sashelp.vcolumn
where libname="WORK" and memname="HAVE" 
and name contains '2016';
quit;

data want;
set have;
array sumv2015 {*} &amp;amp;vr2015;
array sumv2016 {*} &amp;amp;vr2016;
new_sum_2015=sum (of sumv2015{*});
new_sum_2016=sum (of sumv2016{*});
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 24 Jun 2016 11:54:39 GMT</pubDate>
    <dc:creator>Loko</dc:creator>
    <dc:date>2016-06-24T11:54:39Z</dc:date>
    <item>
      <title>sume observations on the base of variable content</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sume-observations-on-the-base-of-variable-content/m-p/279947#M56497</link>
      <description>&lt;P&gt;Dear expert,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;let's assume the following data set:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;abc2016, bcd2015, a2015b, cd2016&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;10, 5, 2, 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how can I sum filtering for the variables containing a certain value?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;expected result:&lt;/P&gt;&lt;P&gt;- 2016: 13&lt;/P&gt;&lt;P&gt;- 2015: 7&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 11:36:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sume-observations-on-the-base-of-variable-content/m-p/279947#M56497</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-06-24T11:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: sume observations on the base of variable content</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sume-observations-on-the-base-of-variable-content/m-p/279949#M56498</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if you need it one time you can hard code it&amp;nbsp; as in my example otherwise you shall write a macro .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd;
input abc2016 bcd2015 a2015b cd2016;
datalines;
10, 5, 2, 3
;
run;

proc sql noprint;
select name into :vr2015 separated by ' ' from
sashelp.vcolumn
where libname="WORK" and memname="HAVE" 
and name contains '2015';
select name into :vr2016 separated by ' ' from
sashelp.vcolumn
where libname="WORK" and memname="HAVE" 
and name contains '2016';
quit;

data want;
set have;
array sumv2015 {*} &amp;amp;vr2015;
array sumv2016 {*} &amp;amp;vr2016;
new_sum_2015=sum (of sumv2015{*});
new_sum_2016=sum (of sumv2016{*});
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jun 2016 11:54:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sume-observations-on-the-base-of-variable-content/m-p/279949#M56498</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2016-06-24T11:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: sume observations on the base of variable content</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sume-observations-on-the-base-of-variable-content/m-p/279952#M56499</link>
      <description>&lt;P&gt;A similar alturnative if your data is tall instead of wide.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.example;
	input variable1 $ value;
	datalines;
	abc2016 10
	bcd2015 5
	a2015b 2
	cd2016 3
	;
run;

proc sql;
	select case when variable1 contains "2015" then 2015
		when variable1 contains "2016" then 2016
		else 0 end as year
		, sum(value) as values
	from work.example
	group by calculated year
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 12:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sume-observations-on-the-base-of-variable-content/m-p/279952#M56499</guid>
      <dc:creator>Urban_Science</dc:creator>
      <dc:date>2016-06-24T12:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: sume observations on the base of variable content</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sume-observations-on-the-base-of-variable-content/m-p/279953#M56500</link>
      <description>&lt;P&gt;Edit, as apposed to the above solutions, there is no hardcoding, and this will work for any number of numeric columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another good example on how changing the structure of your data makes your programming life much easier. &amp;nbsp;Remember the data that comes out of coding doessn't have to be the strcuture that you use for your coding. &amp;nbsp;Make your life as simple as possible:&lt;/P&gt;
&lt;PRE&gt;data have;
  abc2016=10;
  bcd2015=5;
  a2015b=2;
  cd2016=3;
run;
proc transpose data=have out=inter;
  var _numeric_;
run;
proc sql;
  create table WANT as
  select  distinct
          compress(_NAME_," ","a") as COL1,
          sum(COL1) as RESULT
  from    INTER
  group by compress(_NAME_," ","a");
quit;&lt;/PRE&gt;
&lt;P&gt;This normalises your data, so that the year appears as "data" rather than as columns. &amp;nbsp;You only need to know there is an identifier and a result then, simple.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 12:06:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sume-observations-on-the-base-of-variable-content/m-p/279953#M56500</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-24T12:06:49Z</dc:date>
    </item>
  </channel>
</rss>

