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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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