BookmarkSubscribeRSS Feed
icedcoffee3011
Calcite | Level 5

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? 

icedcoffee3011_0-1688576253671.png

*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. 

2 REPLIES 2
Tom
Super User Tom
Super User

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. ;
Kurt_Bremser
Super User

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;

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1175 views
  • 0 likes
  • 3 in conversation