- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello everyone,
I have a categorical variable, plan_type, that is comprised of 9 levels, A, B, C, D, E, F, G, H, I. I want to combine B and C into a new variable to produce a proc freq table of the statistics. I also want to combine D, E, F, and G into one variable, and H and I into their own variable.
The goal is to produce frequency tables like this using proc freq and tables statements:
Plan Type | |||||||||||
A | B | C | D | E | F | G | H | I | Total | ||
Race/Ethnicity | White | 10 | 5 | 2 | 456 | 156 | 486 | 123 | 4869 | 123 | |
Black | 156 | 8469 | 5468 | 546 | 546 | 86947 | 31 | 84 | 320 | ||
Hispanic | 465 | 486 | 568 | 837 | 195 | 86 | 158 | 963 | 71 | ||
Other | 17 | 752 | 6382 | 5781 | 5714 | 72 | 85 | 185 | 81 | ||
Total |
(the values here are not the values I'm working with and are just an example)
I have tried this code:
data health_data;
set health_data;
if plan_type=('A' 'B')
then variable='A_and_B';
run;
And it returned the error:
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You create a custom format, apply it to variable PLAN_TYPE, and then re-run PROC FREQ.
proc format;
value $combf 'B','C'='BC' 'D','E','F','G'='DEFG' 'H','I'='HI';
run;
proc freq;
/* whatever your code was before should go here, plus the following line */
format plan_type $combf.;
run;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You create a custom format, apply it to variable PLAN_TYPE, and then re-run PROC FREQ.
proc format;
value $combf 'B','C'='BC' 'D','E','F','G'='DEFG' 'H','I'='HI';
run;
proc freq;
/* whatever your code was before should go here, plus the following line */
format plan_type $combf.;
run;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This worked beautifully! Thank you, your solution also helped me learn how to use the $ operator.
I appreciate it!