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;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.