<?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: Merging variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-variables/m-p/269961#M53551</link>
    <description>&lt;P&gt;Your question is unclear.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Post what you have, as identical as possible, and what you want. Ideally, what you've tried as well and what isn't working.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 12 May 2016 05:17:10 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-05-12T05:17:10Z</dc:date>
    <item>
      <title>Merging variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-variables/m-p/269955#M53547</link>
      <description>&lt;P&gt;Hi I have a dataset with 3 variables that have the following freqs for each of the variables by year&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var1*year &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;2000 &amp;nbsp; 2001 &amp;nbsp; 2002 &amp;nbsp; &amp;nbsp;2003 &amp;nbsp;2004 &amp;nbsp;2005 &amp;nbsp;2006 &amp;nbsp;2007 &amp;nbsp;&lt;SPAN&gt;2008 &amp;nbsp;2009 &amp;nbsp;2010 &amp;nbsp;2011 &amp;nbsp;2012&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;22 &amp;nbsp; &amp;nbsp; &amp;nbsp; 34 &amp;nbsp; &amp;nbsp; &amp;nbsp; 43 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21 &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;33 &amp;nbsp; &amp;nbsp; &amp;nbsp; 44 &amp;nbsp; &amp;nbsp; &amp;nbsp; 17 &amp;nbsp; &amp;nbsp; &amp;nbsp; 13 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var2*year&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2000 &amp;nbsp; 2001 &amp;nbsp; 2002 &amp;nbsp; &amp;nbsp;2003 &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;2004 &amp;nbsp;2005 &amp;nbsp;2006 &amp;nbsp;2007 &lt;/SPAN&gt;&lt;SPAN&gt;2008 &amp;nbsp;2009 &amp;nbsp;2010 &amp;nbsp;2011 2012&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 35 &amp;nbsp; &amp;nbsp; &amp;nbsp;24 &amp;nbsp; &amp;nbsp; &amp;nbsp;42 &amp;nbsp; &amp;nbsp; &amp;nbsp;22 &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 54 &amp;nbsp; &amp;nbsp; &amp;nbsp;13 &amp;nbsp; &amp;nbsp; &amp;nbsp;24 &amp;nbsp; &amp;nbsp; &amp;nbsp;16 &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var3*year&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2000 &amp;nbsp; 2001 &amp;nbsp; 2002 &amp;nbsp; &amp;nbsp;2003 &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;2004 &amp;nbsp;2005 &amp;nbsp;2006 &amp;nbsp;2007 &lt;/SPAN&gt;&lt;SPAN&gt;2008 2009 2010 2011 2012&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; 33 &amp;nbsp; &amp;nbsp; 54 &amp;nbsp; &amp;nbsp; &amp;nbsp;23 &amp;nbsp; &amp;nbsp;14 &amp;nbsp; &amp;nbsp; 78&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 65 &amp;nbsp; &amp;nbsp; 44 &amp;nbsp; &amp;nbsp; 123 &amp;nbsp; &amp;nbsp;34 &amp;nbsp; &amp;nbsp;89&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So I need to join these 3 variables into one variable using only years 2000-2003 for var1, 2004 to 2007 for var2 and 2008-2012 for var3.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2016 04:23:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-variables/m-p/269955#M53547</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2016-05-12T04:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: Merging variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-variables/m-p/269961#M53551</link>
      <description>&lt;P&gt;Your question is unclear.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Post what you have, as identical as possible, and what you want. Ideally, what you've tried as well and what isn't working.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2016 05:17:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-variables/m-p/269961#M53551</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-12T05:17:10Z</dc:date>
    </item>
    <item>
      <title>Re: Merging variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-variables/m-p/270082#M53609</link>
      <description>&lt;P&gt;Do you have your data in SAS? Since you can't have a variable named "2000" then that structure you demonstrate woule have to have many more variables with different names than implied.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And how are you "joining" variables? Concatenate, add, multiply or something else entirely?&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2016 14:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-variables/m-p/270082#M53609</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-12T14:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Merging variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-variables/m-p/270087#M53612</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/47035"&gt;@mayasak﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe this can be a start:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
     if year in (2000:2003) then var_new=var1;
else if year in (2004:2007) then var_new=var2;
else if year in (2008:2012) then var_new=var3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can compare your PROC FREQ output to that of the following step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=want;
tables var_new*year;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2016 15:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-variables/m-p/270087#M53612</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-05-12T15:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: Merging variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-variables/m-p/270740#M53837</link>
      <description>&lt;P&gt;Thank you &lt;SPAN class="login-bold"&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733" target="_self"&gt;FreelanceReinhard&lt;/A&gt;. That was perfect. I also wanted to know how merge the variables without considering the years so that I can compare both sets and see if there are any overlaps within the different variables for the same years.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 17:51:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-variables/m-p/270740#M53837</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2016-05-16T17:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Merging variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-variables/m-p/270757#M53840</link>
      <description>&lt;P&gt;Without considering the years, you could use the COALESCE function to obtain an aggregated ("merged")&amp;nbsp;variable (by taking the first non-missing value, if any, from VAR1, VAR2, VAR3 in each observation):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2a;
set have;
var_new=coalesce(of var1-var3);
run;

proc compare data=want2a c=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All differences shown in the PROC COMPARE output would be due to "overlaps" of "different variables for the same years." However, there can be overlaps without affecting the PROC COMPARE output, for example if VAR1 and VAR2 had (possibly different) non-missing values in an observation of the year 2000, VAR_NEW in&amp;nbsp;both WANT and WANT2A would have the value from VAR1. Therefore, I wouldn't recommend this approach in general.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would rather look at the combinations of VAR1 - VAR3:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2b;
length varcomb $30; /* please adapt the length as appropriate */
set have;
varcomb=catx(of var1-var3);
run;

proc freq data=want2b order=freq;
tables varcomb;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, overlaps can be clearly recognized in the PROC FREQ output. For instance, a value VARCOMB='1,.,0' would mean "VAR1=1, VAR2=. (missing), VAR3=0." Typically, the corresponding frequency of such combinations will be low. Due to the ORDER= option these exceptional cases will&amp;nbsp;appear closer to the bottom of the frequency table, whereas the predominant cases will be found in the first few rows of the table.&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 18:58:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-variables/m-p/270757#M53840</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-05-16T18:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: Merging variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-variables/m-p/270801#M53851</link>
      <description>&lt;P&gt;I'm not sure if I'm doing the right thing. Let me explain what I'm supposed to do.&lt;/P&gt;&lt;P&gt;The data is for cancer and the three variables are for cancer staging. The problem is that the staging schemes&amp;nbsp;for cancer changed throughout the years. So the first variable is for staging used from year 1988 to 2000. The second variable from year 2001-2003 and the third for years 2004 to 2003. However, I found that there were overlap in years using different staging schemes. What I have to do is to compare between the total cases per each year vs the number of records returned with a populated field value for each respective year/ staging scheme.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've attached Freq tests for the var2*year and var3*year&lt;/P&gt;&lt;P&gt;Also &amp;nbsp;&lt;/P&gt;&lt;P&gt;CombVar*year (using “if year in” codes that you provided in the beginning)&lt;/P&gt;&lt;P&gt;And&lt;/P&gt;&lt;P&gt;VarComb*year&amp;nbsp;&amp;nbsp; (using the coalesce statement)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 22:22:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-variables/m-p/270801#M53851</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2016-05-16T22:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: Merging variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-variables/m-p/271075#M53920</link>
      <description>&lt;P&gt;Thanks for clarifying that this is about cancer staging schemes and for the attached cross(?)-tabulations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I find it confusing that both the tables in your initial post and the new ones have titles suggesting cross-tabulations (var1*year etc.), but have &lt;EM&gt;no row headers&lt;/EM&gt;. This makes it difficult to compare different tables appropriately, because it is not clear which categories (rows) in different tables should be compared.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each of the tables in the attachment has a total row at the bottom, which can be guessed only from the numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you use variable name VarComb (which I used for the CATX-concatenated variable) for a variable derived using the COALESCE function (an approach which I advised against).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The attached tables present a different picture than those in your initial post: Table "var3*year" in your initial post suggested that for the years 2004-2006 VAR3 has only very few non-missing values. The attached table with the same title, however, shows large numbers in all (displayed) categories. At the same time, table "Var2*year" has substantial numbers in only two of the eight categories shown. Of course, this must have to do with the significant change in the assignment of years to variables which has occurred between your initial and current post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tend to believe that, at the current stage, this is not a programming question. You should rather talk to a medical expert who is familiar with those different cancer staging schemes and who can advise you if and how different schemes can be unified for further analysis.&amp;nbsp;As soon as you can describe the rule clearly, many forum members will be able to help you implementing it in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 19:41:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-variables/m-p/271075#M53920</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-05-17T19:41:27Z</dc:date>
    </item>
  </channel>
</rss>

