<?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: Calculating differences pre / post intervention - two different datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculating-differences-pre-post-intervention-two-different/m-p/533883#M146429</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/260616"&gt;@webster1002&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I could be missing something, but can this be adapted if the two data sets already exist, since you cannot include datalines/cards in a macro?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, you could create customized RENAME statements in a SAS macro variable, using PROC CONTENTS and PROC SQL, or create customized RENAME statements in a loop as above; however, since &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt; has come up with a very good solution, I'll stop here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Feb 2019 11:51:46 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-02-08T11:51:46Z</dc:date>
    <item>
      <title>Calculating differences pre / post intervention - two different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-differences-pre-post-intervention-two-different/m-p/533736#M146366</link>
      <description>&lt;P&gt;I need to calculate the change in a set of variables measured before and after an intervention. I have two data sets (pre and post). Each of the variable names are the same in each data set, and they are all paired by an ID variable. There are over 50 variables where I need to calculate the difference.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I can merge the data sets and rename one "pre" or "post" then use a PAIRED statement in PROC TTEST to compare their means, or create a difference variable for individual comparisons. Since there are &amp;gt;50 variables to compare, is there a way to either batch-rename them, and then compare them/calculate differences in a merged data set, or some other way to compare the variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On SAS 9.4 (/STAT IML 14.3)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data look something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data pre;
input ID WT HT BMI SBP STRAIN EF ...;
datalines;
...
...
;
run;

data post;
input ID WT HT BMI SBP STRAIN EF ...;
datalines;
...
...
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2019 20:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-differences-pre-post-intervention-two-different/m-p/533736#M146366</guid>
      <dc:creator>webster1002</dc:creator>
      <dc:date>2019-02-07T20:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating differences pre / post intervention - two different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-differences-pre-post-intervention-two-different/m-p/533740#M146370</link>
      <description>&lt;P&gt;Probably a macro loop would work changing WT to PRE_WT and so on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis;
    %let names=WT HT ... ;
    %let prestring=;
    %let poststring=;
    %do i=1 %to %sysfunc(countw(&amp;amp;names));
        %let thisname=%scan(&amp;amp;names,&amp;amp;i,%str( ));
        %let prestring=&amp;amp;prestring pre_&amp;amp;thisname;
        %let poststring=&amp;amp;poststring post_&amp;amp;thisname;
    %end;
    data pre;
        input id &amp;amp;prestring;
        ...
     run;
    data post;
        input id &amp;amp;poststring;
        ...
     run;
    data both;
        merge pre post;
        by id;
    run;
    proc ttest data=both;
        paired (&amp;amp;prestring):(&amp;amp;poststring);
    run;
%mend;
%dothis
        &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2019 21:19:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-differences-pre-post-intervention-two-different/m-p/533740#M146370</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-07T21:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating differences pre / post intervention - two different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-differences-pre-post-intervention-two-different/m-p/533762#M146383</link>
      <description>&lt;P&gt;I could be missing something, but can this be adapted if the two data sets already exist, since you cannot include datalines/cards in a macro?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2019 21:44:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-differences-pre-post-intervention-two-different/m-p/533762#M146383</guid>
      <dc:creator>webster1002</dc:creator>
      <dc:date>2019-02-07T21:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating differences pre / post intervention - two different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-differences-pre-post-intervention-two-different/m-p/533766#M146386</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/260616"&gt;@webster1002&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could let PROC COMPARE calculate the differences and then perform a one-sample t-test on the differences, which is the same as a paired t-test:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc compare data=pre c=post noprint out=diff(drop=_:);
var _numeric_;
id id;
run;

proc ttest data=diff;
var _numeric_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If not all numeric variables are to be compared, please adapt the variable list (&lt;FONT face="courier new,courier"&gt;_numeric_&lt;/FONT&gt;) to your needs. We can help you with this, too.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2019 22:08:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-differences-pre-post-intervention-two-different/m-p/533766#M146386</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-02-07T22:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating differences pre / post intervention - two different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-differences-pre-post-intervention-two-different/m-p/533883#M146429</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/260616"&gt;@webster1002&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I could be missing something, but can this be adapted if the two data sets already exist, since you cannot include datalines/cards in a macro?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, you could create customized RENAME statements in a SAS macro variable, using PROC CONTENTS and PROC SQL, or create customized RENAME statements in a loop as above; however, since &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt; has come up with a very good solution, I'll stop here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2019 11:51:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-differences-pre-post-intervention-two-different/m-p/533883#M146429</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-08T11:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating differences pre / post intervention - two different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-differences-pre-post-intervention-two-different/m-p/533927#M146443</link>
      <description>Worked perfectly, thank you!</description>
      <pubDate>Fri, 08 Feb 2019 14:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-differences-pre-post-intervention-two-different/m-p/533927#M146443</guid>
      <dc:creator>webster1002</dc:creator>
      <dc:date>2019-02-08T14:32:19Z</dc:date>
    </item>
  </channel>
</rss>

