A Concise Display of Multiple Response Items Patrick Thornton.

Post on 26-Dec-2015

215 views 0 download

Tags:

Transcript of A Concise Display of Multiple Response Items Patrick Thornton.

A Concise Display of Multiple Response Items

Patrick Thornton

Multiple Response Items: Outline

Example item, response & indicator variables

Summarize responses using indicator variables and a PROC FREQ

Summarizing responses into a single table

– Create binary variable from indicators variables

– Create a decimal variable from the binary

– Create a MULTILABEL format for the decimal

– Summarize responses in PROC TABULATE

Conclusion

Multiple Response Item with Example Responses

Are you proficient at speaking the following languages (answer all that apply)?

– Spanish (yes)

– English (yes)

– Chinese (no)

Language Indicator Variables to Store the Responses

data mydata;

length e1-e3 gender 8.;

label e1 = 'Spanish' e2='English' e3='Chinese' gender='Gender';

input e1 e2 e3 gender;

cards;

1 1 0 1

;run;

Formatting Language Indicator Variables

proc format;

value yesno 1 = 'Yes' 0 = 'No';

value gender 1 ='Male' 2 = 'Female';

run;

data mydata;

set mydata;

format e1-e3 yesno. gender gender.;

run;

Using PROC FREQ and the Indicator Variables to Display Language Responses

TITLE1 “Standard Reporting Generates a Table for Each Variable”;

PROC FREQ data=mydata;

TABLE e1-e3;

run;

Using PROC FREQ and the Indicator Variables to Display Language Responses

Using PROC FREQ and the Indicator Variables to Display Language Responses

Using PROC TABULATE to Display the Language Responses

Creating Binary Variable from the Indicator Variables

data mydata;

set mydata;

length language_binary $3.;

language_binary = strip(catt(of e3 e2 e1));

run;

List Indicator and Binary Variables

Create a MULTILABEL Format based on 3 Character Binary Variable

Proc format;

value $langf (multilabel notsorted )

'000' = 'Missing'

'001','011','101','111' = 'Spanish'

'010','011','110','111'= 'English'

'100','101','110','111'='Chinese';

run;

List Indicator and Binary Variables

Create a MULTILABEL Format based on 2 Character Binary Variable

Proc format;

value $langf (multilabel notsorted)

'00' = 'Missing'

'01','11' = 'Spanish'

'10','11', = 'English';

Run;

Creating Binary and Decimal Variables from the Indicator Variables

data mydata;

set mydata;

length language_binary $3. language_profile 8.;

language_binary = strip(catt(of e3 e2 e1));

language_profile=input(language_binary,binary3.);

run;

Listing of Binary and Decimal Variables

MULTILABEL Format to Label Decimal Values

Proc format;

value langf (multilabel notsorted )

0 = 'Missing'

1,3,5,7 = 'Spanish'

2,3,6,7= 'English'

4,5,6,7= 'Chinese';

Run;

PROC TABULATE, MULTILABEL, and Decimal Variable

proc tabulate data=mydata ;

class language_profile /ORDER=DATA PRELOADFMT MLF;

table language_profile="Language" all='Total',

(n* format=10.0 pctn='%'*format=7.1)/

box='Table 1 Student reported language proficiency'

rtspace=20;

format language_profile $langf. ;

run;

Single Table Display of Multiple Response Language Item

PROC TABULATE, MULTILABEL, Decimal Variable, and Column Variable

proc tabulate data=mydata ;

class language_profile /ORDER=DATA PRELOADFMT MLF;

class gender;

table language_profile="Language" all='Total', gender*

(n* format=10.0 pctn='%'*format=7.1)/

box='Table 2 Student reported language proficiency by gender'

rtspace=20;

format language_profile $langf. ;

run;

Single Table Display of Multiple Response Language Item and Gender

Macro Program for Creating the Multi-Label Format

Thornton, P. (2013). A Concise Display of Multiple Response Items. Proceedings of the 2013 SAS Global Forum, San Francisco, CA

Bonus: BAND Function – Is it useful?

BAND is a function that performs a bitwise AND operation on two arguments

– The result is a multiplication of each position in the binary form of two numbers

– x=BAND (arg1,arg2)

• Arg1 = 001

• Arg2 = 001

• X = 1

– By passing 001 as Arg2, I can confirm a 1 is in the same position in Arg1

Is it useful to subset OBS with BAND?

proc print data=mydata label;

var language_binary language_profile e3-e1;

where e1 = 1;

run;

proc print data=mydata label;

var language_binary language_profile e3-e1;

where band(language_profile,001);

run;

Test of the BAND Function

Test of the BAND Function (con’t)

It does seem possible to subset OBS based on BAND

proc print data=example label;

var language_binary language_profile e6-e1;

where band(language_profile,101010);

run;

Data subset;

set example;

if band(language_profile,101010);

Run;

Conclusion

Creating binary and decimal variables from a series of indicator variables is useful

– Display responses with PROC TABULATE and MULTILABEL format

– A macro program can be used to build the format

Limitation

– Observations where missing responses cannot be considered a “no” response must be removed from the display

– Maximum of about 10 indicators (ie. 2**10-1 combinations)

SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries. ® indicates USA registration.

Other brand and product names are registered trademarks or Trademarks of their respective companies.

The Power

To Know™

SAS®

Contact Information

Patrick Thornton, Ph.D.

333 Ravenswood Ave

Menlo Park, CA 94025-3493

650 859-5583

Patrick.thornton@sri.com