<?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 Selecting earliest/latest date for t-test in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selecting-earliest-latest-date-for-t-test/m-p/467000#M119184</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data points collected at 3 dates (in SAS format) for each patient and need to select the first and third in order to find averages for the data point and perform a ttest. How would I do this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I came across a similar question and saw people suggest&amp;nbsp;a method using &lt;STRONG&gt;proc sql&lt;/STRONG&gt; but will this just give me an output listing what the first/third dates are or will it reorganize the dataset? My instructor told me I need to create 2 files and merge them so do I create a file for the first date then one for the third and then merge them? Thanks for any help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a sample and as you can see, the dates are not ordered.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;ML&lt;/TD&gt;&lt;TD&gt;SF&lt;/TD&gt;&lt;TD&gt;date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;37&lt;/TD&gt;&lt;TD&gt;39&lt;/TD&gt;&lt;TD&gt;4/5/2013&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;24&lt;/TD&gt;&lt;TD&gt;29&lt;/TD&gt;&lt;TD&gt;2/26/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;TD&gt;36&lt;/TD&gt;&lt;TD&gt;12/15/2012&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;68&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;12/31/2010&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;76&lt;/TD&gt;&lt;TD&gt;88&lt;/TD&gt;&lt;TD&gt;7/24/2013&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;68&lt;/TD&gt;&lt;TD&gt;86&lt;/TD&gt;&lt;TD&gt;12/17/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;70&lt;/TD&gt;&lt;TD&gt;95&lt;/TD&gt;&lt;TD&gt;6/20/2013&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;71&lt;/TD&gt;&lt;TD&gt;95&lt;/TD&gt;&lt;TD&gt;4/14/2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;TD&gt;95&lt;/TD&gt;&lt;TD&gt;6/21/2011&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&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;</description>
    <pubDate>Fri, 01 Jun 2018 20:19:31 GMT</pubDate>
    <dc:creator>iressa131</dc:creator>
    <dc:date>2018-06-01T20:19:31Z</dc:date>
    <item>
      <title>Selecting earliest/latest date for t-test</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-earliest-latest-date-for-t-test/m-p/467000#M119184</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data points collected at 3 dates (in SAS format) for each patient and need to select the first and third in order to find averages for the data point and perform a ttest. How would I do this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I came across a similar question and saw people suggest&amp;nbsp;a method using &lt;STRONG&gt;proc sql&lt;/STRONG&gt; but will this just give me an output listing what the first/third dates are or will it reorganize the dataset? My instructor told me I need to create 2 files and merge them so do I create a file for the first date then one for the third and then merge them? Thanks for any help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a sample and as you can see, the dates are not ordered.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;ML&lt;/TD&gt;&lt;TD&gt;SF&lt;/TD&gt;&lt;TD&gt;date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;37&lt;/TD&gt;&lt;TD&gt;39&lt;/TD&gt;&lt;TD&gt;4/5/2013&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;24&lt;/TD&gt;&lt;TD&gt;29&lt;/TD&gt;&lt;TD&gt;2/26/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;TD&gt;36&lt;/TD&gt;&lt;TD&gt;12/15/2012&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;68&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;12/31/2010&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;76&lt;/TD&gt;&lt;TD&gt;88&lt;/TD&gt;&lt;TD&gt;7/24/2013&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;68&lt;/TD&gt;&lt;TD&gt;86&lt;/TD&gt;&lt;TD&gt;12/17/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;70&lt;/TD&gt;&lt;TD&gt;95&lt;/TD&gt;&lt;TD&gt;6/20/2013&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;71&lt;/TD&gt;&lt;TD&gt;95&lt;/TD&gt;&lt;TD&gt;4/14/2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;TD&gt;95&lt;/TD&gt;&lt;TD&gt;6/21/2011&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&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;</description>
      <pubDate>Fri, 01 Jun 2018 20:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-earliest-latest-date-for-t-test/m-p/467000#M119184</guid>
      <dc:creator>iressa131</dc:creator>
      <dc:date>2018-06-01T20:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting earliest/latest date for t-test</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-earliest-latest-date-for-t-test/m-p/467006#M119185</link>
      <description>&lt;P&gt;Do you want to calculate the average value between first and third records? Then check this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date mmddyy10. val;
datalines;
05/28/2018 10
05/29/2018 20
05/30/2018 30
;
run;

data want;
merge have have(keep=val firstobs=2 rename=(val=Val_));
lag_val=Lag(Val);
Avg=Val_+Lag_val/2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jun 2018 19:45:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-earliest-latest-date-for-t-test/m-p/467006#M119185</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-06-01T19:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting earliest/latest date for t-test</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-earliest-latest-date-for-t-test/m-p/467015#M119186</link>
      <description>It depends on how your data is structured. For example, is it structured so that those 3 dates are all in one row or multiple rows. Please post some sample data, fake is fine, just needs to reflect your data structure.</description>
      <pubDate>Fri, 01 Jun 2018 20:05:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-earliest-latest-date-for-t-test/m-p/467015#M119186</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-01T20:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting earliest/latest date for t-test</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-earliest-latest-date-for-t-test/m-p/467020#M119188</link>
      <description>&lt;P&gt;Sorry! I uploaded a sample just now&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jun 2018 20:20:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-earliest-latest-date-for-t-test/m-p/467020#M119188</guid>
      <dc:creator>iressa131</dc:creator>
      <dc:date>2018-06-01T20:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting earliest/latest date for t-test</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-earliest-latest-date-for-t-test/m-p/467025#M119189</link>
      <description>There are always more than one way to accomplish things. &lt;BR /&gt;&lt;BR /&gt;1. Sort by ID&lt;BR /&gt;2. Use BY processing and FIRST/LAST to get the first and last record (or third).&lt;BR /&gt;3. Depends on what statistics you're wanting. If you provide that remaining detail we can help direct you on that stage as well.</description>
      <pubDate>Fri, 01 Jun 2018 20:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-earliest-latest-date-for-t-test/m-p/467025#M119189</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-01T20:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting earliest/latest date for t-test</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-earliest-latest-date-for-t-test/m-p/467051#M119200</link>
      <description>&lt;P&gt;so even though the date arent in order SAS will identify first and last correctly? I'm looking to get the&amp;nbsp;means for all variables at the first and third time point and compare the first and third SF score by way of a paired t test.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jun 2018 23:06:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-earliest-latest-date-for-t-test/m-p/467051#M119200</guid>
      <dc:creator>iressa131</dc:creator>
      <dc:date>2018-06-01T23:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting earliest/latest date for t-test</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-earliest-latest-date-for-t-test/m-p/467053#M119201</link>
      <description>&lt;P&gt;Sort by ID and DATE before you do the analysis.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jun 2018 23:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-earliest-latest-date-for-t-test/m-p/467053#M119201</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-06-01T23:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting earliest/latest date for t-test</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-earliest-latest-date-for-t-test/m-p/467061#M119205</link>
      <description>&lt;P&gt;Ordering of data is trivial, the main issue is understanding what format PROC TTEST would like for the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For a two sample t-test its a long format, for a paired t-test you need them separate or take the difference and use a single t-test on the difference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't explain the 'averages' part and not sure how that relates to a t-test either. Here's an example to help you get started.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
informat date mmddyy10.;
input ID  ML  SF  date;
cards;
1   37  39  4/5/2013
1   24  29  2/26/2015
1   22  36  12/15/2012
3   68  100 12/31/2010
3   76  88  7/24/2013
3   68  86  12/17/2015
4   70  95  6/20/2013
4   71  95  4/14/2016
4   40  95  6/21/2011
;
run;

proc sort data=have; 
by id date;
run;

data filtered;
set have;
by id date;
if first.id or last.id then do;
if first.id then count=1; else count=2;output;
end;

run;

proc ttest data=filtered;
class count;
var ml sf;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Jun 2018 01:22:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-earliest-latest-date-for-t-test/m-p/467061#M119205</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-02T01:22:10Z</dc:date>
    </item>
  </channel>
</rss>

