Hello,
I have a multiple choice data set in which respondents can select more than one answer (select all that apply). The Excel sheet separates these multiple answers with a comma (i.e. 1,3). Value labels are assigned in the syntax but SAS groups these numbers into one new number; therefore, there is no value assigned. How can I make SAS separate these multiple answers?
*Frequencies should be: 9 and 3 not 8, 2 and 1*
The image above shows my output for one of the variables. The values are as follows: 1='Intervention clinic', 2='Medical office', and 3='Other'. The 13 in the table is because someone selected options 1 and 3 in the survey.
I hope I am being clear on what I want and appreciate any help.
If you want to convert '1,3' into two separate observations do something like:
data want;
set have ;
single=scan(multiple,1,',');
output;
do i=2 to countw(multiple,',');
single=scan(multiple,1,',');
output;
end;
format single $responce. ;
run;
Now you can run PROC FREQ on the variable SINGLE instead of the original variable MULTIPLE.
If your format for decoding the codes into human recognizable text is a numeric format then use the INPUT() function to convert the string into a number.
...
single=input(scan(multiple,1,','),32.);
...
format single responce. ;
Separate the multiple choices into multiple observations:
data want;
set have (rename=(placeenc=_placeenc));
do i = 1 to countw(_placeenc,",");
placeenc = scan(_placeenc,i,",");
output;
end;
drop i _placeenc;
run;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.