Thank you for your guidance it was very helpful! I didn't use arrays and did the following instead: /*This SAS code allows you to combine open ended survey responses and create new variables or categories to capture the answers specified within the If other specify multiple choice answer*/
*IMPORT: to import the SAS file and create a library*;
libname saslib "\\(ENTER YOUR LIBRARY PATHWAY HERE"; *creates a permanent SAS File. Creating the library allows us to refer to a file in a specific folder.*;
run;
*Look at your dataset*
data year19;
set saslib.survey;
run;
proc contents data=year19 VARNUM out=contents; *VarNUM list the variables in the order that they were created;
run;
proc sort data=year19;
by surveyYears;
run;
/* List variable*/;
proc print data=year19;
var admin educat tech Other OthSpecify;
run;
/*Format the question responses*/
proc format;
value admin educat tech Other OthSpecify;
1="yes" 2="no";
run;
/* Calculate summary statistics */;
proc means data= year19;
var admin educat tech Other OthSpecify;
run;
/* Examine extreme values */ ;
proc univariate data= year19;
var admin educat tech Other OthSpecify;
run;
/* List unique values and frequencies */
proc freq data= year19;
tables admin educat tech Other OthSpecify;
run;
*FINDINGS: In 2019, the survey respondents selected the following multiple choice options (output descriptive statistics listed below and changed for privacy)
1- admin
N: 900 (number of people responding no)/90% (percentage of people responding no)
Y: 100/10%
2- educat
N: 900/90%
Y: 100/10%
3- tech
N: 900/90%
Y: 100/10%
4- Other
N: 900/90%
Y: 100/10%
5- OthSpecify
N: 900/90%
Y: 100/10%
/* if Other, please specify, recoded below*/
*Using one recoding variable*;
data year19_1; /* create a new dataset (name) for SAS to make any changes to your data*/
set year19; /*old dataset name*/
*Create new variables for the categories above that could have been selected as a response. Meaning, some of the OthSpecify responses should have been one of the 4 multiple choice options available*;
admin_recode = 0;
educat_recode = 0;
tech_recode = 0;
Other_recode = 0;
*Here, setting the initial value of these variables to 0. The value will change if the variable meets the criteria outlined below for each observation. Below we recode those other specify responses that belong to one of the existing multiple choice answers.;
if OthSpecify in
("admin assistant"
"adminn"
"admin assistants")
then admin_recode = 1;
/*you are putting all the values that need to be recoded as admin in the ()*/
else if OthSpecify in
"educator"
"educ")
then educat_recode = 1;
else if OthSpecify in
('technology assistant"
"techs")
then tech_recode = 1;
*Create a final variable that will capture all situations where a respondent indicated a response to the multiple choice answer which will = Yes or provided a value for OthSpecify had a write-in answer;
*Create a final admin variable;
if admin_recode = 1 or admin = "Y" then admin_final = 1;
else admin_final = 0;
*Create a final educat variable;
if educat _recode = 1 or educat = "Y" then educat _final = 1;
else educat _final = 0;
*Create a final tech variable;
if tech _recode = 1 or tech = "Y" then tech _final = 1;
else tech _final = 0;
*Create a final Oth variable;
If
admin_final = 0 and
educat_final = 0 and
tech_final = 0 /*make sure to not add the word and to the last variable*/
then OthSpecify_final = 1;
else OthSpecify_final = 0;
run;
*Printing new recodes*;
proc freq data=year19_1;
tables admin_final educat_final tech_final Other_final OthSpecify_final;
run;
proc print data=year19_1;
var admin_final educat_final tech_final Other_final OthSpecify_final;
run;
... View more