<?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: Testing Difference in Mean Between Two Specific Periods - 'MULTIPLE TIMES'. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Testing-Difference-in-Mean-Between-Two-Specific-Periods-MULTIPLE/m-p/450288#M283684</link>
    <description>&lt;P&gt;Of course, there are many ways. The first step in the code above&amp;nbsp;is just there for testing. Create your &lt;STRONG&gt;have&lt;/STRONG&gt; dataset with a datastep using infile&amp;nbsp;or a SQL query or any other means. As long as it contains&amp;nbsp;the &lt;STRONG&gt;date&lt;/STRONG&gt; and &lt;STRONG&gt;x1&lt;/STRONG&gt; variables.&lt;/P&gt;</description>
    <pubDate>Mon, 02 Apr 2018 02:50:09 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2018-04-02T02:50:09Z</dc:date>
    <item>
      <title>Testing Difference in Mean Between Two Specific Periods - 'MULTIPLE TIMES'.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Testing-Difference-in-Mean-Between-Two-Specific-Periods-MULTIPLE/m-p/450059#M283681</link>
      <description>&lt;DIV class="lia-message-heading lia-component-message-header"&gt;&lt;DIV class="lia-quilt-row lia-quilt-row-standard"&gt;&lt;DIV class="lia-quilt-column lia-quilt-column-20 lia-quilt-column-left"&gt;&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-left"&gt;&lt;DIV class="lia-message-subject"&gt;&lt;DIV class="dropdown-positioning"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="lia-message-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to test the difference in mean&amp;nbsp;between two&amp;nbsp;time periods in my data set. However, I need to carry out this test multiple times.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Precisely, for each&lt;STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;'date'&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;in my data; I need to test the difference between the mean of '&lt;STRONG&gt;X1&lt;/STRONG&gt;' for&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;'30 days before&lt;/STRONG&gt;' and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;'30 days after'.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code below works perfectly, but I need to manually specify each date (which is obviously too cumbersome). I would sincerely appreciate some suggestions!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Present Code:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;/*date of interest:&amp;nbsp;&lt;SPAN&gt;16May2001*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data xx;&lt;BR /&gt;set x;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Startdate1 = '16May2001'd - 30;&lt;BR /&gt;Enddate1 = '16May2001'd;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Startdate2 = '17May2001'd;&lt;BR /&gt;Enddate2 = '17May2001'd + 30;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If Startdate1 &amp;lt; date &amp;lt; Enddate1 then flag=0;&lt;BR /&gt;If Startdate2 &amp;lt; date &amp;lt; Enddate2 then flag=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc ttest data=xx;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;class flag;&lt;/P&gt;&lt;P&gt;var X1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Sample Data:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;(Date Format: mmddyear)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;X1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1/2/2001&lt;/TD&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5/16/2001&lt;/TD&gt;&lt;TD&gt;34&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5/26/2001&lt;/TD&gt;&lt;TD&gt;65&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5/27/2001&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6/8/2001&lt;/TD&gt;&lt;TD&gt;56&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10/11/2001&lt;/TD&gt;&lt;TD&gt;31&lt;/TD&g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ubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Testing-Difference-in-Mean-Between-Two-Specific-Periods-MULTIPLE/m-p/450059#M283681</guid>
      <dc:creator>arii</dc:creator>
      <dc:date>2018-03-30T20:23:57Z</dc:date>
    </item>
    <item>
      <title>Re: Testing Difference in Mean Between Two Specific Periods - 'MULTIPLE TIMES'.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Testing-Difference-in-Mean-Between-Two-Specific-Periods-MULTIPLE/m-p/450107#M283682</link>
      <description>&lt;P&gt;Here is one approach using a self join:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Date :mmddyy. X1; 
format date yymmdd10.;
datalines;
1/2/2001 22 
5/16/2001 34 
5/26/2001 65 
5/27/2001 11 
6/8/2001 56 
10/11/2001 31 
12/12/2001 91 
1/13/2004 49 
7/18/2005 56 
9/19/2006 21 
12/2/2007 67 
12/21/2007 34 
12/29/2007 67 
1/23/2008 90 
7/14/2008 78 
9/25/2008 45 
6/28/2009 45 
1/29/2010 54 
;

proc sql;
create table test as
select
    a.date as middate,
    b.date &amp;gt; a.date as period,
    b.date,
    b.x1
from 
    have as a inner join
    have as b 
      on b.date between intnx('day',a.date,-30) and intnx('day',a.date,30) and
      a.date ne b.date
group by middate
having count(distinct period) = 2
order by middate, date;
quit;

ods select none;

proc ttest data=test plots=none;
ods output ttests=tt;
by middate;
class period;
var x1;
run;

ods select all;

proc print data=tt; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 31 Mar 2018 04:24:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Testing-Difference-in-Mean-Between-Two-Specific-Periods-MULTIPLE/m-p/450107#M283682</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-03-31T04:24:26Z</dc:date>
    </item>
    <item>
      <title>Re: Testing Difference in Mean Between Two Specific Periods - 'MULTIPLE TIMES'.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Testing-Difference-in-Mean-Between-Two-Specific-Periods-MULTIPLE/m-p/450244#M283683</link>
      <description>&lt;P&gt;Thank you for your response, PG Stats.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to do this without the&lt;STRONG&gt; 'datalines'&amp;nbsp;&lt;/STRONG&gt;in the code?&amp;nbsp;My actual data has close to 500 observations and the 'datalines approach' would be kinda clumsy for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Apr 2018 16:10:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Testing-Difference-in-Mean-Between-Two-Specific-Periods-MULTIPLE/m-p/450244#M283683</guid>
      <dc:creator>arii</dc:creator>
      <dc:date>2018-04-01T16:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: Testing Difference in Mean Between Two Specific Periods - 'MULTIPLE TIMES'.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Testing-Difference-in-Mean-Between-Two-Specific-Periods-MULTIPLE/m-p/450288#M283684</link>
      <description>&lt;P&gt;Of course, there are many ways. The first step in the code above&amp;nbsp;is just there for testing. Create your &lt;STRONG&gt;have&lt;/STRONG&gt; dataset with a datastep using infile&amp;nbsp;or a SQL query or any other means. As long as it contains&amp;nbsp;the &lt;STRONG&gt;date&lt;/STRONG&gt; and &lt;STRONG&gt;x1&lt;/STRONG&gt; variables.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Apr 2018 02:50:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Testing-Difference-in-Mean-Between-Two-Specific-Periods-MULTIPLE/m-p/450288#M283684</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-04-02T02:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Testing Difference in Mean Between Two Specific Periods - 'MULTIPLE TIMES'.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Testing-Difference-in-Mean-Between-Two-Specific-Periods-MULTIPLE/m-p/451363#M283685</link>
      <description>&lt;P&gt;Hi PGStats,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, I am still struggling with the codes you supplied (please pardon my basic SAS&amp;nbsp;knowledge).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the &lt;STRONG&gt;data-set approach&lt;/STRONG&gt; because I have already created a data-set from my main data file. I have over a thousand observations, I don't think the 'datalines approach' would work well for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I still have lots of errors in the log file. I am not too sure what is wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See the modified code I used below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; xxx;&lt;BR /&gt;&lt;STRONG&gt;set&lt;/STRONG&gt; xx;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;input Date :mmddyy. X1;&lt;BR /&gt;format date yymmdd10.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table test as&lt;BR /&gt;select&lt;BR /&gt;a.date as middate,&lt;BR /&gt;b.date &amp;gt; a.date as period,&lt;BR /&gt;b.date,&lt;BR /&gt;b.x1&lt;BR /&gt;from&lt;BR /&gt;have as a inner join&lt;BR /&gt;have as b&lt;BR /&gt;on b.date between intnx('day',a.date,-30) and intnx('day',a.date,30) and&lt;BR /&gt;a.date ne b.date&lt;BR /&gt;group by middate&lt;BR /&gt;having count(distinct period) = 2&lt;BR /&gt;order by middate, date;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;ods select none;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc ttest data=test plots=none;&lt;BR /&gt;ods output ttests=tt;&lt;BR /&gt;by middate;&lt;BR /&gt;class period;&lt;BR /&gt;var x1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods select all;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc print data=tt; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;See some errors from log file:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ERROR&lt;/STRONG&gt;: No DATALINES or INFILE statement.&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ERROR&lt;/STRONG&gt;: Variable MIDDATE not found.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ERROR&lt;/STRONG&gt;: File WORK.TT.DATA does not exist&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 01:23:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Testing-Difference-in-Mean-Between-Two-Specific-Periods-MULTIPLE/m-p/451363#M283685</guid>
      <dc:creator>arii</dc:creator>
      <dc:date>2018-04-05T01:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: Testing Difference in Mean Between Two Specific Periods - 'MULTIPLE TIMES'.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Testing-Difference-in-Mean-Between-Two-Specific-Periods-MULTIPLE/m-p/451376#M283686</link>
      <description>&lt;P&gt;The first thing you must do is to&amp;nbsp;bring your data into a SAS dataset. That is often the first difficulty that new users encounter. Where is your main data file?&lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 02:44:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Testing-Difference-in-Mean-Between-Two-Specific-Periods-MULTIPLE/m-p/451376#M283686</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-04-05T02:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: Testing Difference in Mean Between Two Specific Periods - 'MULTIPLE TIMES'.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Testing-Difference-in-Mean-Between-Two-Specific-Periods-MULTIPLE/m-p/451743#M283687</link>
      <description>&lt;P&gt;I have attached the main data file herein.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 02:04:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Testing-Difference-in-Mean-Between-Two-Specific-Periods-MULTIPLE/m-p/451743#M283687</guid>
      <dc:creator>arii</dc:creator>
      <dc:date>2018-04-06T02:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: Testing Difference in Mean Between Two Specific Periods - 'MULTIPLE TIMES'.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Testing-Difference-in-Mean-Between-Two-Specific-Periods-MULTIPLE/m-p/451747#M283689</link>
      <description>&lt;P&gt;I doubt I had issues with the data import. My main challenge was with conducting the 'proc t test' multiple times - using the dates in my data file as a reference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached my full codes herein.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help, PGStats.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 02:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Testing-Difference-in-Mean-Between-Two-Specific-Periods-MULTIPLE/m-p/451747#M283689</guid>
      <dc:creator>arii</dc:creator>
      <dc:date>2018-04-06T02:15:09Z</dc:date>
    </item>
  </channel>
</rss>

