<?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 Subtracting values from 2 datasets/arrays in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Subtracting-values-from-2-datasets-arrays/m-p/68625#M19666</link>
    <description>Hello,&lt;BR /&gt;
I'm not sure if this is the correct forum to pose this question, but  . . . &lt;BR /&gt;
I have 2 datasets which have the same variables/observations.  For my project., i need to subtract one from the other, but i have a small problem.  If i go to do it with proc iml, creating arrays with the values, iml does not work if a value=0, and i happen to have quite a few values of zero.  Anyone have ideas of what i can do?  Thanks!</description>
    <pubDate>Mon, 30 Aug 2010 20:20:53 GMT</pubDate>
    <dc:creator>CharlesR</dc:creator>
    <dc:date>2010-08-30T20:20:53Z</dc:date>
    <item>
      <title>Subtracting values from 2 datasets/arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subtracting-values-from-2-datasets-arrays/m-p/68625#M19666</link>
      <description>Hello,&lt;BR /&gt;
I'm not sure if this is the correct forum to pose this question, but  . . . &lt;BR /&gt;
I have 2 datasets which have the same variables/observations.  For my project., i need to subtract one from the other, but i have a small problem.  If i go to do it with proc iml, creating arrays with the values, iml does not work if a value=0, and i happen to have quite a few values of zero.  Anyone have ideas of what i can do?  Thanks!</description>
      <pubDate>Mon, 30 Aug 2010 20:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subtracting-values-from-2-datasets-arrays/m-p/68625#M19666</guid>
      <dc:creator>CharlesR</dc:creator>
      <dc:date>2010-08-30T20:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting values from 2 datasets/arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subtracting-values-from-2-datasets-arrays/m-p/68626#M19667</link>
      <description>Hi:&lt;BR /&gt;
  First I had to make some data, so I used SASHELP.CLASS and made 2 different versions of it with some changed values (so there would be differences) and with some 0 values. &lt;BR /&gt;
 &lt;BR /&gt;
  Then I used PROC SQL to join the two tables by NAME and do the subtraction. I kept EVERYTHING...so you could see what might be useful to you. If you did not want negative numbers, then you might use the ABS function to remove the - sign from the subtraction (as shown for the ABSAGEDIFF variable).&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
** make a version of SASHELP.CLASS with different values for;&lt;BR /&gt;
** age, height and weight;&lt;BR /&gt;
data class;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
  age = age + 5;&lt;BR /&gt;
  height = height * 1.05;&lt;BR /&gt;
  weight = weight * 1.05;&lt;BR /&gt;
  ** make a few 0 obs;&lt;BR /&gt;
  if name = 'John' then do;&lt;BR /&gt;
     age = 0;&lt;BR /&gt;
     height=0;&lt;BR /&gt;
     weight = 0;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
                          &lt;BR /&gt;
** make some obs with 0 in a second copy of sashelp.class;&lt;BR /&gt;
data class2;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
  if name in ('Janet', 'Alfred') then do;&lt;BR /&gt;
     age = 0;&lt;BR /&gt;
     height=0;&lt;BR /&gt;
     weight = 0;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
                                                      &lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table newdiff as&lt;BR /&gt;
  select a.name, a.sex, a.age, a.height, a.weight,&lt;BR /&gt;
         b.age as b_age, b.height as b_height, b.weight as b_weight,&lt;BR /&gt;
         a.age - b.age as agediff,&lt;BR /&gt;
         a.height - b.height as htdiff,&lt;BR /&gt;
         a.weight - b.weight as wtdiff,&lt;BR /&gt;
         abs(a.age - b.age) as absagediff&lt;BR /&gt;
  from work.class as a,&lt;BR /&gt;
       work.class2 as b&lt;BR /&gt;
  where a.name = b.name&lt;BR /&gt;
  order by name;&lt;BR /&gt;
  quit;&lt;BR /&gt;
                        &lt;BR /&gt;
proc print data=work.newdiff;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 30 Aug 2010 21:09:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subtracting-values-from-2-datasets-arrays/m-p/68626#M19667</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-08-30T21:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting values from 2 datasets/arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subtracting-values-from-2-datasets-arrays/m-p/68627#M19668</link>
      <description>You may also want to consider PROC COMPARE depending on what you're looking for, particularily if its validation.  &lt;BR /&gt;
&lt;BR /&gt;
Even If its just two data sets with same variables/observations in the same order then Proc Compare can help automate some of that, see&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://www.lexjansen.com/pharmasug/2003/tutorials/tu056.pdf" target="_blank"&gt;http://www.lexjansen.com/pharmasug/2003/tutorials/tu056.pdf&lt;/A&gt;</description>
      <pubDate>Mon, 30 Aug 2010 21:42:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subtracting-values-from-2-datasets-arrays/m-p/68627#M19668</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2010-08-30T21:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting values from 2 datasets/arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subtracting-values-from-2-datasets-arrays/m-p/68628#M19669</link>
      <description>Charles,&lt;BR /&gt;
&lt;BR /&gt;
If AND ONLY IF your data is exactly like you described, and there REALLY is a one for one match between the two files (i.e., if record N in the first file is always the same individual as record N in the second file) then a simple data step would also work.&lt;BR /&gt;
&lt;BR /&gt;
For example, using Cynthia's test data (with one exception):&lt;BR /&gt;
&lt;BR /&gt;
** make a version of SASHELP.CLASS with different values for;&lt;BR /&gt;
** age, height and weight;&lt;BR /&gt;
data class;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
  age = age + 5;&lt;BR /&gt;
  height = height * 1.05;&lt;BR /&gt;
  weight = weight * 1.05;&lt;BR /&gt;
  ** make a few 0 AND MISSINGobs;&lt;BR /&gt;
  if name = 'John' then do;&lt;BR /&gt;
     age = 0;&lt;BR /&gt;
     call missing(height);&lt;BR /&gt;
     weight = 0;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
** make some obs with 0 in a second copy of sashelp.class;&lt;BR /&gt;
data class2;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
  if name in ('Janet', 'Alfred') then do;&lt;BR /&gt;
     age = 0;&lt;BR /&gt;
     height=0;&lt;BR /&gt;
     weight = 0;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want;&lt;BR /&gt;
  set class;&lt;BR /&gt;
  set class2(keep=age height weight&lt;BR /&gt;
              rename=(age=b_age&lt;BR /&gt;
                      height=b_height&lt;BR /&gt;
                      weight=b_weight));&lt;BR /&gt;
  age_diff=sum(age-b_age);&lt;BR /&gt;
  height_diff=sum(height-b_height);&lt;BR /&gt;
  weight_diff=(weight-b_weight);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art</description>
      <pubDate>Mon, 30 Aug 2010 22:14:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subtracting-values-from-2-datasets-arrays/m-p/68628#M19669</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2010-08-30T22:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting values from 2 datasets/arrays</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subtracting-values-from-2-datasets-arrays/m-p/68629#M19670</link>
      <description>hey thanks both of you!  I think i'm going with the data step!  Appreciate the help as always!</description>
      <pubDate>Thu, 02 Sep 2010 02:54:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subtracting-values-from-2-datasets-arrays/m-p/68629#M19670</guid>
      <dc:creator>CharlesR</dc:creator>
      <dc:date>2010-09-02T02:54:19Z</dc:date>
    </item>
  </channel>
</rss>

