BookmarkSubscribeRSS Feed
kmaz
Calcite | Level 5

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;

 

2 REPLIES 2
Reeza
Super User

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;

 


 

 

ballardw
Super User

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;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 962 views
  • 0 likes
  • 3 in conversation