<?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: Effect size by substracting two separate datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Effect-size-by-substracting-two-separate-datasets/m-p/799811#M314537</link>
    <description>&lt;P&gt;If you don't have IML, try (assumes that both datasets are sorted by id)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.substract;
   set work.data1 work.data2;
   by id;
   
   array vars c1-c4;
   
   do i = 1 to dim(vars);
      vars[i] = dif(vars[i]) * -1;
   end;
   
   if last.id;
   
   drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 03 Mar 2022 12:08:17 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2022-03-03T12:08:17Z</dc:date>
    <item>
      <title>Effect size by substracting two separate datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Effect-size-by-substracting-two-separate-datasets/m-p/799790#M314523</link>
      <description>&lt;P&gt;I have 80 patients measured on 200 variables at two timepoints. Two separate datasets were generated with identical IDs of patients and identical variables in the same order. I'm intrested&amp;nbsp; in the effect between the two timepoints by substracting each variable from&amp;nbsp; its corresponding in the other dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I give examples of the datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data1:&lt;/P&gt;
&lt;P&gt;id,C1,C2,C3,C4&lt;BR /&gt;1,4.10855,5.44574,33.16678,6.75791&lt;BR /&gt;3,3.48004,6.29138,31.34662,10.38753&lt;BR /&gt;4,2.33851,5.84293,35.79064,11.0801&lt;BR /&gt;9,3.1966,7.15718,30.27008,7.49836&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data2:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id,C1,C2,C3,C4&lt;BR /&gt;1,4.19855,5.74574,33.46678,6.85391&lt;BR /&gt;3,3.48004,6.69138,31.85662,11.73753&lt;BR /&gt;4,3.33851,5.74293,36.09064,10.9801&lt;BR /&gt;9,3.2966,8.15718,30.27008,7.62836&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 10:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Effect-size-by-substracting-two-separate-datasets/m-p/799790#M314523</guid>
      <dc:creator>Job04</dc:creator>
      <dc:date>2022-03-03T10:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Effect size by substracting two separate datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Effect-size-by-substracting-two-separate-datasets/m-p/799809#M314535</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/324234"&gt;@Job04&lt;/a&gt;&amp;nbsp;, if you have IML licensed this is as simple as performing subtraction between two matrices, assuming as you say that you have the same IDs in the same order for both datasets. Simple code example below&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Read dummy data in;
data work.data1;
input id $ c1 c2 c3 c4 ;
datalines;
1 4.10855 5.44574 33.16678 6.75791
3 3.48004 6.29138 31.34662 10.38753
4 2.33851 5.84293 35.79064 11.0801
9 3.1966 7.15718 30.27008 7.49836
;

data work.data2;
input id $ c1 c2 c3 c4 ;
datalines;
1 4.19855 5.74574 33.46678 6.85391
3 3.48004 6.69138 31.85662 11.73753
4 3.33851 5.74293 36.09064 10.9801
9 3.2966 8.15718 30.27008 7.62836
;

*IML Procedure to load tables and perform matrix difference;

proc iml;
title 'Run IML Procedure';
*read data 1;
use work.data1;
   read all var _NUM_ into A[colname=varNames]; 

print A;

*read data 2;
use work.data2;
   read all var _NUM_ into B[colname=varNames]; 

print B;

*matrix difference;
diff = A-B;
print diff;

*Save output;
create work.diff from diff[colname=varNames];
append from diff;                               
close; 
quit;

*Join IDs to output table;
data work.diff_out;
set work.data1(keep=id) ;
set work.diff;
run;

proc print data=work.diff_out;title 'Results as SAS Dataset with IDs';quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Output should look something like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HarrySnart_0-1646307132763.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69103i1606A44B607D5FF4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HarrySnart_0-1646307132763.png" alt="HarrySnart_0-1646307132763.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Harry&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 11:32:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Effect-size-by-substracting-two-separate-datasets/m-p/799809#M314535</guid>
      <dc:creator>HarrySnart</dc:creator>
      <dc:date>2022-03-03T11:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: Effect size by substracting two separate datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Effect-size-by-substracting-two-separate-datasets/m-p/799811#M314537</link>
      <description>&lt;P&gt;If you don't have IML, try (assumes that both datasets are sorted by id)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.substract;
   set work.data1 work.data2;
   by id;
   
   array vars c1-c4;
   
   do i = 1 to dim(vars);
      vars[i] = dif(vars[i]) * -1;
   end;
   
   if last.id;
   
   drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Mar 2022 12:08:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Effect-size-by-substracting-two-separate-datasets/m-p/799811#M314537</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-03-03T12:08:17Z</dc:date>
    </item>
  </channel>
</rss>

