BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
aayomiposi
Calcite | Level 5

Hi Everyone,

I have this survey data that includes checkboxes (select all that apply), and I am trying to create a new variable that groups all of these separate variables into a new variable. An individual can check more than one role or facility. I am new with SAS, and I know using "Else if" would not give the right frequencies (since its for mutually exclusive responses). Initially, I was going to use macro since I had a lot of variables to recategorize, but I couldn't get it to work so I decided to go with this but still not getting the right frequencies for each category. Can anyone help correct the code below, and let me know what I might be doing wrong thank you? SAS 9.4

 

*creating a new category called "respondent's role"*;
Data FSurvey1;
set FSurvey;
if respondent_role___1= 1 then role=1;
if respondent_role___2= 1 then role=2;
if respondent_role___3= 1 then role=3;
if respondent_role___4= 1 then role=4;
if respondent_role___5= 1 then role=5;
if respondent_role___6= 1 then role=6;
if respondent_role___7= 1 then role=7;
if respondent_role___8= 1 then role=8;


*creating a new category called "facilities description"*;
if facility_description___1= 1 then facility=1;
if facility_description___2= 1 then facility=2;
if facility_description___3= 1 then facility=3;
if facility_description___4= 1 then facility=4;
if facility_description___5= 1 then facility=5;
if facility_description___6= 1 then facility=6;
if facility_description___7= 1 then facility=7;
if facility_description___8= 1 then facility=8;
format facility facility. role role.;
run;
proc freq data= FSurvey1;
tables facility role;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Okay, I think I understand. I believe this is what you want:

 

Data FoamSurvey1;
set FoamSurvey;
if respondent_role___1= 1 then do; role=1; output; end;
if respondent_role___2= 1 then do; role=2; output; end;
if respondent_role___3= 1 then do; role=3; output; end;
if respondent_role___4= 1 then do; role=4; output; end;
if respondent_role___5= 1 then do; role=5; output; end;
if respondent_role___6= 1 then do; role=6; output; end;
if respondent_role___7= 1 then do; role=7; output; end;
if respondent_role___8= 1 then do; role=8; output; end;
format role roles.;
run;
--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

So, if for a given respondent, the value of respondent_role___1 is equal to 1 and the value of respondent_role___3 is equal to 1 and the value of respondent_role___5 is equal to 1, what result do you want?

 

Would this work?

 

proc freq data= FSurvey1;
tables facility_desc: respondent_role: ;
run;
--
Paige Miller
aayomiposi
Calcite | Level 5

Thank you for your response. That worked and I got this

aayomiposi_0-1673534999061.png

 

So, 0= unchecked, and 1= checked, meaning that for each of those variables for example respondent role__1, we have 1 and 0. All of the different variables should be in a variable as categories and not as an individual variable. So i need SAS to count everyone that checked role 1 as one category irrespective of if they checked other roles. 

PaigeMiller
Diamond | Level 26

@aayomiposi wrote:

 

So, 0= unchecked, and 1= checked, meaning that for each of those variables for example respondent role__1, we have 1 and 0. All of the different variables should be in a variable as categories and not as an individual variable. So i need SAS to count everyone that checked role 1 as one category irrespective of if they checked other roles. 


I don't understand these words. Categories that look like what? SHOW US what you want.

--
Paige Miller
aayomiposi
Calcite | Level 5

So when I use this code
Data FoamSurvey1;
set FoamSurvey;
if respondent_role___1= 1 then role=1;
if respondent_role___2= 1 then role=2;
if respondent_role___3= 1 then role=3;
if respondent_role___4= 1 then role=4;
if respondent_role___5= 1 then role=5;
if respondent_role___6= 1 then role=6;
if respondent_role___7= 1 then role=7;
if respondent_role___8= 1 then role=8;
format role roles.
run;
proc freq data= FoamSurvey1;
tables role;
run;

 

I get this,

aayomiposi_0-1673535752590.png

This is how I want it categorized. However, it is not correct. State fire training director should be 11 not 10, deputy fire chief should be 10 not 8. 

PaigeMiller
Diamond | Level 26

Okay, I think I understand. I believe this is what you want:

 

Data FoamSurvey1;
set FoamSurvey;
if respondent_role___1= 1 then do; role=1; output; end;
if respondent_role___2= 1 then do; role=2; output; end;
if respondent_role___3= 1 then do; role=3; output; end;
if respondent_role___4= 1 then do; role=4; output; end;
if respondent_role___5= 1 then do; role=5; output; end;
if respondent_role___6= 1 then do; role=6; output; end;
if respondent_role___7= 1 then do; role=7; output; end;
if respondent_role___8= 1 then do; role=8; output; end;
format role roles.;
run;
--
Paige Miller
aayomiposi
Calcite | Level 5
Thank you so much. It worked. I appreciate your help and patience.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 6 replies
  • 2192 views
  • 0 likes
  • 2 in conversation