06-01-2018 03:29 PM - edited 06-01-2018 04:19 PM
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?
I came across a similar question and saw people suggest a method using proc sql 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!
Here is a sample and as you can see, the dates are not ordered.
06-01-2018 03:45 PM
Do you want to calculate the average value between first and third records? Then check this
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;
06-01-2018 04:05 PM
06-01-2018 04:31 PM
06-01-2018 07:06 PM
so even though the date arent in order SAS will identify first and last correctly? I'm looking to get the 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.
06-01-2018 09:22 PM
Ordering of data is trivial, the main issue is understanding what format PROC TTEST would like for the data.
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.
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.
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;