DATA Step, Macro, Functions and more

PROC TTEST 2 sample independent t test

Reply
Occasional Learner
Posts: 1

PROC TTEST 2 sample independent t test

Hi, I'm taking a SAS class and we are doing statistical test programming. I'm trying to run a PROC TTEST on HISTCOR1 and AGE_P, where AGE_P was formatted into 2 groups, but technically there are three groups. There following is my code, with the format for AGE_P given by my professor. The PROC TTEST won't run because there's more than 2 levels, which makes no sense because my WHERE statement says to look only at 18 year old and older.

 

OPTIONS NOFMTERR;
RUN;


LIBNAME Mydata 'U:\PUBHBIO 6270\Lab_12';
RUN;


PROC CONTENTS DATA=Mydata.personsx08;
RUN;

 

PROC FORMAT;
VALUE AGE_P_fmt 18-40='Younger Adults'
41>='Older Adults';
RUN;

 

PROC TTEST DATA=Mydata.personsx08 ALPHA=0.05 SIDED=2;
VAR HICOSTR1;
WHERE HICOSTR1 not in (99997,99998,99999) AND AGE_P >=18;
CLASS AGE_P;
FORMAT AGE_P AGE_P_fmt.;
TITLE "Mean out-of-pocket premium cost (Plan1): Younger Adults vs. Older Adults";
RUN;

 

Super User
Posts: 23,237

Re: PROC TTEST 2 sample independent t test

Works fine for me. 

See this example below, check if it runs on your machine. 

If it works, there's a bug in your code somewhere. If not, something else is wrong.

 

Please include your log in the future, often the culprit can easily be found by scanning the log.

 

proc format;
value age_fmt
low - 13 = 'Pre Teen'
13 - high = 'Teen';
run;


PROC TTEST DATA=sashelp.class ALPHA=0.05 SIDED=2;
CLASS age ;
format age age_fmt.;
VAR weight;
RUN;

@kmaz wrote:

Hi, I'm taking a SAS class and we are doing statistical test programming. I'm trying to run a PROC TTEST on HISTCOR1 and AGE_P, where AGE_P was formatted into 2 groups, but technically there are three groups. There following is my code, with the format for AGE_P given by my professor. The PROC TTEST won't run because there's more than 2 levels, which makes no sense because my WHERE statement says to look only at 18 year old and older.

 

OPTIONS NOFMTERR;
RUN;


LIBNAME Mydata 'U:\PUBHBIO 6270\Lab_12';
RUN;


PROC CONTENTS DATA=Mydata.personsx08;
RUN;

 

PROC FORMAT;
VALUE AGE_P_fmt 18-40='Younger Adults'
41>='Older Adults';
RUN;

 

PROC TTEST DATA=Mydata.personsx08 ALPHA=0.05 SIDED=2;
VAR HICOSTR1;
WHERE HICOSTR1 not in (99997,99998,99999) AND AGE_P >=18;
CLASS AGE_P;
FORMAT AGE_P AGE_P_fmt.;
TITLE "Mean out-of-pocket premium cost (Plan1): Younger Adults vs. Older Adults";
RUN;

 


 

 

Super User
Posts: 13,293

Re: PROC TTEST 2 sample independent t test

Your format is incorrect. If you run proc freq with that format on your data you will see that ages 41 and above show the numeric value.

Your format should be (assuming integer age values)

PROC FORMAT ;
VALUE AGE_P_fmt 18-40='Younger Adults'
41-high='Older Adults';
RUN;
Ask a Question
Discussion stats
  • 2 replies
  • 114 views
  • 0 likes
  • 3 in conversation