Here's an example of how you can create a format and apply it. You can run the code and examine the output, it should work in any version of SAS.
/*this is an example of creating a custom format and then applying it to a data set*/
*create the format;
proc format;
value age_group
low - 13 = 'Pre-Teen'
13 - 15 = 'Teen'
16 - high = 'Adult';
run;
title 'Example of an applied format';
proc print data=sashelp.class;
format age age_group.; *applies the format;
run;
data class;
set sashelp.class;
age_category = put(age, age_group.); *creates a character variable with the age category;
label age_category = 'Age Category'; *adds a nice label for the printed output;
run;
title 'Example of creating a new variable with the format';
proc print data=class label;
run;
*show format used directly;
proc freq data=sashelp.class;
table age / out= formatted_age;
format age age_group.;
run;
For your specific group your format would look like:
proc format;
value days_category
1-2 = "1 to 2 days"
3-5 = "3 to 5 days"
6-7 = "6 to 7 days"
99 = "Missing";
run;
Then apply it in your code:
proc anova data=WORK.AGEPHYSICALHEALTH;
class PAQ670;
format paq670 days_category.;
model RIDAGEYR = PAQ670;
means PAQ670 / scheffe;
title;
run;
@Monaghan wrote:
Hello! I am trying to perform a one way ANOVA comparison of merged data. I have been able to merge the data, but I am having trouble with combining some variable data. I am wanting to look at the variable of age (RIDAGEYR) with the variable of days of physical activity per week (PAQ670) . For my project, I would like to group the days into 3 categories (1-2 days, 3-5 days, 6-7 days) and run a ANOVA test to get the mean age for each of the three categories. I have been able to run the ANOVA, but not able to separate the wanted categories. Here is my code and output--
data work. agephysicalhealth; merge SASFILE.DEMO_H SASFILE.PAQ_H; by SEQN; run;
proc anova data=WORK.AGEPHYSICALHEALTH; class PAQ670; model RIDAGEYR = PAQ670; means PAQ670 / scheffe; title; run;
The output lists the *class PAQ670 and values 1 2 3 4 5 6 7 99*
I have not figured out how to separate these - not sure if I should sort the data prior to running the procedure or sort after. I would like to use the same code for all of my procedures because I am running multiple analysis on the variable of days of physical activity.
Thank you for any help!!
Carrie
... View more