<?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: Merge/Combine datasets - summing like variables.  SAS 9.4 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-Combine-datasets-summing-like-variables-SAS-9-4/m-p/329665#M73802</link>
    <description>&lt;P&gt;Try an inner join and I have assumed the variable 'time' could be used as a key. This should give you the desired results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
select a.geo, a.time, 
	a.web_wib_aln,
	a.web_wib_ccd,
	a.web_wib_dch,
	a.web_wib_dsv,
	a.web_wib_efs,
	a.web_wib_hel,
	a.web_wib_iau,
	b.web_wib_ilh,
	b.web_wib_inv,
	b.web_wib_mtg,
	b.web_wib_onl
from have1 as a
inner join have2 as b 
on a.time=b.time ;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 03 Feb 2017 03:00:39 GMT</pubDate>
    <dc:creator>anoopmohandas7</dc:creator>
    <dc:date>2017-02-03T03:00:39Z</dc:date>
    <item>
      <title>Merge/Combine datasets - summing like variables.  SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Combine-datasets-summing-like-variables-SAS-9-4/m-p/329659#M73799</link>
      <description>&lt;P&gt;Hello - thanks in advance for your time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have dataset1 with 100+ variables and dataset2 with 100+ variables. &amp;nbsp;Some of the variables match across the two datasets. &amp;nbsp;I'm looking for a dataset3 that is the sum of the matching variables but also includes the unique variables from each dataset. &amp;nbsp;I understand this is a relatively simple task by renaming the variables, merging the datasets and summing the like variables manually. However I'm looking to remove any manual processes from this program as I receive this data often and these manual steps are driving me crazy! &amp;nbsp;Additionally, the variable naming conventions do not follow any sequence, i.e., x1 - xn. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input geo time 
	web_wib_aln
	web_wib_ccd
	web_wib_dch
	web_wib_dsv
	web_wib_efs
	web_wib_hel
	web_wib_iau;
datalines;
501 209 0 0 1 2 3 4 5
501 210 0 0 1 2 3 4 5
501 211 0 0 1 2 3 4 5
;
RUN;

data have2;
input geo time 
	web_wib_ccd
	web_wib_dch
	web_wib_dsv
	web_wib_ilh
	web_wib_inv
	web_wib_mtg
	web_wib_onl;
datalines;
501 209 6 7 8 9 10 11 12
501 210 6 7 8 9 10 11 12 
501 211 6 7 8 9 10 11 12
;
RUN;

The dataset I'm looking for:

data want;
input geo time
	web_wib_ccd
	web_wib_dch
	web_wib_dsv
	web_wib_aln
	web_wib_efs
	web_wib_hel
	web_wib_iau
	web_wib_ilh
	web_wib_inv
	web_wib_mtg
	web_wib_onl;
datalines;
501	209	11	8	10	1	3	4	5	9	10	11	12
501	210	9	8	10	1	3	4	5	9	10	11	12
501	211	10	8	10	1	3	4	5	9	10	11	12
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Again, thanks for your time and input!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2017 02:10:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Combine-datasets-summing-like-variables-SAS-9-4/m-p/329659#M73799</guid>
      <dc:creator>antwon</dc:creator>
      <dc:date>2017-02-03T02:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: Merge/Combine datasets - summing like variables.  SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Combine-datasets-summing-like-variables-SAS-9-4/m-p/329665#M73802</link>
      <description>&lt;P&gt;Try an inner join and I have assumed the variable 'time' could be used as a key. This should give you the desired results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
select a.geo, a.time, 
	a.web_wib_aln,
	a.web_wib_ccd,
	a.web_wib_dch,
	a.web_wib_dsv,
	a.web_wib_efs,
	a.web_wib_hel,
	a.web_wib_iau,
	b.web_wib_ilh,
	b.web_wib_inv,
	b.web_wib_mtg,
	b.web_wib_onl
from have1 as a
inner join have2 as b 
on a.time=b.time ;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Feb 2017 03:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Combine-datasets-summing-like-variables-SAS-9-4/m-p/329665#M73802</guid>
      <dc:creator>anoopmohandas7</dc:creator>
      <dc:date>2017-02-03T03:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Merge/Combine datasets - summing like variables.  SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Combine-datasets-summing-like-variables-SAS-9-4/m-p/329672#M73807</link>
      <description>&lt;P&gt;If we can assume that the math in your example doesn't add up correctly, then the following might do what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  set have2 have1;
run;

proc summary data=want nway;
  var web_:;
  class geo time;
  output out=want (drop=_:) sum=;
run;
&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2017 03:43:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Combine-datasets-summing-like-variables-SAS-9-4/m-p/329672#M73807</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-03T03:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: Merge/Combine datasets - summing like variables.  SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Combine-datasets-summing-like-variables-SAS-9-4/m-p/329845#M73846</link>
      <description>Thank you, anoopmohandas7! But I was looking to take the manual process of typing variable names out of the program for the reason that the datasets actually include 200+ variables. art297's example below worked well. Thanks for your time and input - its much appreciated!</description>
      <pubDate>Fri, 03 Feb 2017 17:39:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Combine-datasets-summing-like-variables-SAS-9-4/m-p/329845#M73846</guid>
      <dc:creator>antwon</dc:creator>
      <dc:date>2017-02-03T17:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: Merge/Combine datasets - summing like variables.  SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Combine-datasets-summing-like-variables-SAS-9-4/m-p/329853#M73851</link>
      <description>&lt;P&gt;art297 - this is brilliant! &amp;nbsp;And yes, your assumption is absolutely correct - I must have copied/pasted the wrong table. &amp;nbsp;I didn't even think to use proc summary and I didn't realize you could specify all variables&amp;nbsp;beginning with "web_" in the command. &amp;nbsp;This perfectly&amp;nbsp;solves my dilemma - thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2017 17:46:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Combine-datasets-summing-like-variables-SAS-9-4/m-p/329853#M73851</guid>
      <dc:creator>antwon</dc:creator>
      <dc:date>2017-02-03T17:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: Merge/Combine datasets - summing like variables.  SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Combine-datasets-summing-like-variables-SAS-9-4/m-p/329855#M73853</link>
      <description>Concerned about this merge.....&lt;BR /&gt;Obviously only numerics can be summed.&lt;BR /&gt;What about character vars. Are these the keys?&lt;BR /&gt;If so, no column names are needed in the prog.&lt;BR /&gt;Data v/ view= v ;&lt;BR /&gt;Set dataset1 dataset2 ;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;proc summary noprint nway  data = v ;&lt;BR /&gt;Class   _character_ &lt;BR /&gt;Var     _ numeric_ ;&lt;BR /&gt;Output  out= want( drop= _: ) sum= ;&lt;BR /&gt;Run;&lt;BR /&gt;</description>
      <pubDate>Fri, 03 Feb 2017 17:53:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Combine-datasets-summing-like-variables-SAS-9-4/m-p/329855#M73853</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-02-03T17:53:58Z</dc:date>
    </item>
  </channel>
</rss>

