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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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