Statistical Procedures

Programming the statistical procedures from SAS
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bazingarollcall
Fluorite | Level 6

Hello everyone,

I've hit a wall with my own knowledge and am having a hard time finding the key words to search for topics to solve this problem via google or communities like this.
 
 

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       
  ABCDEFGHITotal
Race/EthnicityWhite10524561564861234869123 
 Black15684695468546546869473184320 
 Hispanic4654865688371958615896371 
 Other17752638257815714728518581 
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: 

ERROR 180-322: Statement is not valid or it is used out of proper order.
 
Any ideas?
 
 
Thank you.  
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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
bazingarollcall
Fluorite | Level 6
Hi Paige,

This worked beautifully! Thank you, your solution also helped me learn how to use the $ operator.

I appreciate it!

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 3206 views
  • 1 like
  • 2 in conversation