<?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: Calculate differences and mean between rows with same suffix in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Calculate-differences-and-mean-between-rows-with-same-suffix/m-p/607500#M17540</link>
    <description>&lt;P&gt;Yes I do, and that worked perfectly. Thanks, Paige!&lt;/P&gt;</description>
    <pubDate>Tue, 26 Nov 2019 20:34:36 GMT</pubDate>
    <dc:creator>bkq32</dc:creator>
    <dc:date>2019-11-26T20:34:36Z</dc:date>
    <item>
      <title>Calculate differences and mean between rows with same suffix</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-differences-and-mean-between-rows-with-same-suffix/m-p/607492#M17538</link>
      <description>&lt;P&gt;I started with two SAS data sets (reader + gold standard) with several body measurement values, added prefixes to differentiate which data set they came from, and merged them by ID to get something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input ID $4. READER_ARM READER_LEG GOLD_ARM GOLD_LEG ;
 cards;
A123 5 8 2 6 9 2
B543 1 6 2 3 4 4
C859 4 7 2 5 8 4
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to calculate the difference and mean between variables with the same suffix to end up with:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;

 DIFF_ARM=READER_ARM-GOLD_ARM;
 DIFF_LEG=READER_LEG-GOLD_LEG;

 MEAN_ARM=(READER_ARM+GOLD_ARM)/2;
 MEAN_LEG=(READER_LEG+GOLD_LEG)/2;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Since my actual data set has many body measurement variables, how can I simplify this with an array or macro? I can rename the variables too if that makes it easier.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 20:09:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-differences-and-mean-between-rows-with-same-suffix/m-p/607492#M17538</guid>
      <dc:creator>bkq32</dc:creator>
      <dc:date>2019-11-26T20:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate differences and mean between rows with same suffix</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-differences-and-mean-between-rows-with-same-suffix/m-p/607494#M17539</link>
      <description>&lt;P&gt;If you know the list of suffixes in advance, you could easily write a macro to do this. (Do you know the list of suffixes in advance?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis(suffixes=);
    %let nsuffix=%sysfunc(countw(&amp;amp;suffixes));
    data want;
        set have;
        %do i=1 %to &amp;amp;nsuffix;
             %let thissuffix=%scan(&amp;amp;suffixes,&amp;amp;i,%str( ));
             diff_&amp;amp;thissuffix=sum(reader_&amp;amp;thissuffix,-gold_&amp;amp;thissuffix);
             mean_&amp;amp;thissuffix=mean(read_&amp;amp;thissuffix,gold_&amp;amp;thissuffix);
         %end;
    run;
%mend;
%dothis(suffixes=ARM LEG)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Nov 2019 20:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-differences-and-mean-between-rows-with-same-suffix/m-p/607494#M17539</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-26T20:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate differences and mean between rows with same suffix</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-differences-and-mean-between-rows-with-same-suffix/m-p/607500#M17540</link>
      <description>&lt;P&gt;Yes I do, and that worked perfectly. Thanks, Paige!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 20:34:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-differences-and-mean-between-rows-with-same-suffix/m-p/607500#M17540</guid>
      <dc:creator>bkq32</dc:creator>
      <dc:date>2019-11-26T20:34:36Z</dc:date>
    </item>
  </channel>
</rss>

