<?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: tough one: merge 2 datasets, need to reduce 5 variables to one in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/tough-one-merge-2-datasets-need-to-reduce-5-variables-to-one/m-p/57576#M12430</link>
    <description>Hi Charles&lt;BR /&gt;
&lt;BR /&gt;
You can of course concatenate keys and then use this concatenated string - but if you ever want a SQL query to be able to use indexes then you don't concatenate.&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
    <pubDate>Thu, 28 Apr 2011 10:10:26 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2011-04-28T10:10:26Z</dc:date>
    <item>
      <title>tough one: merge 2 datasets, need to reduce 5 variables to one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/tough-one-merge-2-datasets-need-to-reduce-5-variables-to-one/m-p/57572#M12426</link>
      <description>Hello,&lt;BR /&gt;
I'm trying to do a many-to-many match merge, but i have a problem: rather than having 1 "by" variable, i have 5 "by" variables.  I don't think i can do this in SAS, but it would also work to have the 5 variables compound to one variable showing each of the permutations of the 5, then doing the merge by the new single variable.&lt;BR /&gt;
&lt;BR /&gt;
Can anyone show me how to do this?&lt;BR /&gt;
&lt;BR /&gt;
Thanks!

Message was edited by: CharlesR</description>
      <pubDate>Wed, 27 Apr 2011 05:53:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/tough-one-merge-2-datasets-need-to-reduce-5-variables-to-one/m-p/57572#M12426</guid>
      <dc:creator>CharlesR</dc:creator>
      <dc:date>2011-04-27T05:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: tough one: merge 2 datasets, need to reduce 5 variables to one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/tough-one-merge-2-datasets-need-to-reduce-5-variables-to-one/m-p/57573#M12427</link>
      <description>you can do many to many merging and many to many joining in SAS with multiple by-variables or join-variables&lt;BR /&gt;
 &lt;BR /&gt;
Of course (although you don't need it), you can also collapse 5 columns into one quite simply, like:&lt;BR /&gt;
wide = catx( '/', col1,col3,colA,colC,colB);&lt;BR /&gt;
first making sure you have enough room for all data in column WIDE.&lt;BR /&gt;
When you look up the doc on function catx(), you will find it converts numerics to strings, removes all leading/trailing spaces, and separates the data columns with the first parameter value ( useful when you find you need to re-separate the data).</description>
      <pubDate>Wed, 27 Apr 2011 08:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/tough-one-merge-2-datasets-need-to-reduce-5-variables-to-one/m-p/57573#M12427</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-04-27T08:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: tough one: merge 2 datasets, need to reduce 5 variables to one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/tough-one-merge-2-datasets-need-to-reduce-5-variables-to-one/m-p/57574#M12428</link>
      <description>Hi Charles&lt;BR /&gt;
&lt;BR /&gt;
A bit a more specific question - eventually with sample data and expected result - would help us to understand your question better and give you a more adequate answer.&lt;BR /&gt;
&lt;BR /&gt;
There is quite a bit of docu available in regards of combining SAS datasets and Proc SQL. Below a few links and some example code:&lt;BR /&gt;
&lt;BR /&gt;
Combining SAS datasets:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a001125856.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a001125856.htm&lt;/A&gt; &lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001293108.htm#" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001293108.htm#&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Proc SQL:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000086336.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000086336.htm&lt;/A&gt; &lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473691.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473691.htm&lt;/A&gt; (SQL joining tables)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data have1;&lt;BR /&gt;
  do key1=1,3,5;&lt;BR /&gt;
    do key2=2,4;&lt;BR /&gt;
      var='Have 1';&lt;BR /&gt;
      output;&lt;BR /&gt;
      output;&lt;BR /&gt;
    end;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data have2;&lt;BR /&gt;
  do key1=1,5;&lt;BR /&gt;
    do key2=2;&lt;BR /&gt;
      var='Have 2';&lt;BR /&gt;
      output;&lt;BR /&gt;
      output;&lt;BR /&gt;
    end;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
title1 'Inner Join 1: Many to Many';&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select &lt;BR /&gt;
      l.key1 as l_key1&lt;BR /&gt;
    , l.key2 as l_key2&lt;BR /&gt;
    , l.var  as l_var &lt;BR /&gt;
    , r.key1 as r_key1&lt;BR /&gt;
    , r.key2 as r_key2&lt;BR /&gt;
    , r.var  as r_var &lt;BR /&gt;
  from have1 l,have2 r&lt;BR /&gt;
  where l.key1=r.key1 and l.key2=r.key2&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
title1 'Inner Join 2: Many to Many';&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select &lt;BR /&gt;
      l.key1 as l_key1&lt;BR /&gt;
    , l.key2 as l_key2&lt;BR /&gt;
    , l.var  as l_var &lt;BR /&gt;
    , r.key1 as r_key1&lt;BR /&gt;
    , r.key2 as r_key2&lt;BR /&gt;
    , r.var  as r_var &lt;BR /&gt;
  from have1 l inner join have2 r&lt;BR /&gt;
  on l.key1=r.key1 and l.key2=r.key2&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
title1 'Left Join: Many to Many';&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select &lt;BR /&gt;
      l.key1 as l_key1&lt;BR /&gt;
    , l.key2 as l_key2&lt;BR /&gt;
    , l.var  as l_var &lt;BR /&gt;
    , r.key1 as r_key1&lt;BR /&gt;
    , r.key2 as r_key2&lt;BR /&gt;
    , r.var  as r_var &lt;BR /&gt;
  from have1 l left join have2 r&lt;BR /&gt;
  on l.key1=r.key1 and l.key2=r.key2&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
title1 'Right Join: Many to Many';&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select &lt;BR /&gt;
      l.key1 as l_key1&lt;BR /&gt;
    , l.key2 as l_key2&lt;BR /&gt;
    , l.var  as l_var &lt;BR /&gt;
    , r.key1 as r_key1&lt;BR /&gt;
    , r.key2 as r_key2&lt;BR /&gt;
    , r.var  as r_var &lt;BR /&gt;
  from have1 l right join have2 r&lt;BR /&gt;
  on l.key1=r.key1 and l.key2=r.key2&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
title1 'Outer Join: Many to Many';&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select &lt;BR /&gt;
      l.key1 as l_key1&lt;BR /&gt;
    , l.key2 as l_key2&lt;BR /&gt;
    , l.var  as l_var &lt;BR /&gt;
    , r.key1 as r_key1&lt;BR /&gt;
    , r.key2 as r_key2&lt;BR /&gt;
    , r.var  as r_var &lt;BR /&gt;
  from have1 l full outer join have2 r&lt;BR /&gt;
  on l.key1=r.key1 and l.key2=r.key2&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
title1 'Union Join: Many to Many';&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select *&lt;BR /&gt;
  from have1&lt;BR /&gt;
  union&lt;BR /&gt;
  select *&lt;BR /&gt;
  from have2&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
title1 'Outer Union Join: Many to Many';&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select *&lt;BR /&gt;
  from have1&lt;BR /&gt;
  outer union&lt;BR /&gt;
  select *&lt;BR /&gt;
  from have2&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
title1 'Outer Union Corr Join: Many to Many';&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select *&lt;BR /&gt;
  from have1&lt;BR /&gt;
  outer union Corr&lt;BR /&gt;
  select *&lt;BR /&gt;
  from have2&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick

Message was edited by: Patrick</description>
      <pubDate>Wed, 27 Apr 2011 08:33:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/tough-one-merge-2-datasets-need-to-reduce-5-variables-to-one/m-p/57574#M12428</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2011-04-27T08:33:08Z</dc:date>
    </item>
    <item>
      <title>Re: tough one: merge 2 datasets, need to reduce 5 variables to one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/tough-one-merge-2-datasets-need-to-reduce-5-variables-to-one/m-p/57575#M12429</link>
      <description>That's exactly what i did with concatenation.  You can also create the variable like this:&lt;BR /&gt;
&lt;BR /&gt;
[pre] Scenarios = zone||BallInPlayType||BattedBallVelocity||DblPlayPosn||BatSide||PlayRes_forPerc;[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Thanks a bunch for the help!

Message was edited by: CharlesR</description>
      <pubDate>Thu, 28 Apr 2011 02:47:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/tough-one-merge-2-datasets-need-to-reduce-5-variables-to-one/m-p/57575#M12429</guid>
      <dc:creator>CharlesR</dc:creator>
      <dc:date>2011-04-28T02:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: tough one: merge 2 datasets, need to reduce 5 variables to one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/tough-one-merge-2-datasets-need-to-reduce-5-variables-to-one/m-p/57576#M12430</link>
      <description>Hi Charles&lt;BR /&gt;
&lt;BR /&gt;
You can of course concatenate keys and then use this concatenated string - but if you ever want a SQL query to be able to use indexes then you don't concatenate.&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Thu, 28 Apr 2011 10:10:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/tough-one-merge-2-datasets-need-to-reduce-5-variables-to-one/m-p/57576#M12430</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2011-04-28T10:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: tough one: merge 2 datasets, need to reduce 5 variables to one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/tough-one-merge-2-datasets-need-to-reduce-5-variables-to-one/m-p/57577#M12431</link>
      <description>&amp;gt; That's exactly what i did with concatenation.  You&lt;BR /&gt;
&amp;gt; can also create the variable like this:&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; [pre] Scenarios =&lt;BR /&gt;
&amp;gt; zone||BallInPlayType||BattedBallVelocity||DblPlayPosn|&lt;BR /&gt;
&amp;gt; |BatSide||PlayRes_forPerc;[/pre]&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Thanks a bunch for the help!&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Message was edited by: CharlesR&lt;BR /&gt;
&lt;BR /&gt;
Charles&lt;BR /&gt;
does your form of concatenation (||) remove trailing space on strings and leading blanks on automatically converted numerics?&lt;BR /&gt;
If not you may run out of room in a default new-column width.&lt;BR /&gt;
On the up-side of this risk, at least it will be really easy to parse, as each component will always appear in the same position on the long "SCENARIOS" string.&lt;BR /&gt;
As always, consider the options Patrick draws to your attention - losing the benefits of indexes is sometimes a very high price to pay.&lt;BR /&gt;
 &lt;BR /&gt;
peterC</description>
      <pubDate>Thu, 28 Apr 2011 15:32:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/tough-one-merge-2-datasets-need-to-reduce-5-variables-to-one/m-p/57577#M12431</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-04-28T15:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: tough one: merge 2 datasets, need to reduce 5 variables to one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/tough-one-merge-2-datasets-need-to-reduce-5-variables-to-one/m-p/57578#M12432</link>
      <description>Indeces aren't quite as important as the final set post-proc freq has only 63,000 observations.  &lt;BR /&gt;
&lt;BR /&gt;
And yes, there are spaces which are left over, but the variables are fairly small, so this isn't a huge prob, but you're right, i should concatenate diff.  &lt;BR /&gt;
&lt;BR /&gt;
What's more important is the ability to use the concatenated variable in a merge with another data set.  It's significantly faster to run a merge with a a single variable as the merge by variable, rather than using the group of variables.</description>
      <pubDate>Thu, 28 Apr 2011 17:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/tough-one-merge-2-datasets-need-to-reduce-5-variables-to-one/m-p/57578#M12432</guid>
      <dc:creator>CharlesR</dc:creator>
      <dc:date>2011-04-28T17:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: tough one: merge 2 datasets, need to reduce 5 variables to one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/tough-one-merge-2-datasets-need-to-reduce-5-variables-to-one/m-p/57579#M12433</link>
      <description>&amp;gt; set.  It's significantly faster to run a merge with a&lt;BR /&gt;
&amp;gt; a single variable as the merge by variable, rather&lt;BR /&gt;
&amp;gt; than using the group of variables.&lt;BR /&gt;
 &lt;BR /&gt;
Charles&lt;BR /&gt;
 &lt;BR /&gt;
have you any examples of the effect that reducing your 5 columns to one might have on the merge?&lt;BR /&gt;
 &lt;BR /&gt;
peterC</description>
      <pubDate>Thu, 28 Apr 2011 19:15:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/tough-one-merge-2-datasets-need-to-reduce-5-variables-to-one/m-p/57579#M12433</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-04-28T19:15:33Z</dc:date>
    </item>
  </channel>
</rss>

