Hello - I know questions like mine have been asked before, but I wasn't able to find an answer that I could adapt to my situation. I would like to create a single bar chart with individual bars for several variables in my dataset, where the values for each variable are either 0 or 1 for each record in the dataset.
I created a series of binary (0/1) variables from questions on a survey where respondents could select one more options (e.g. bn_option1, bn_option2, ...) . Now I'd like to create bar charts for the % of '1's for each option (binary variable) of the corresponding question. One bar chart per question with as many bars as there were originally options. Thanks.
First of all, are you looking for help doing this in SAS?
I created a series of binary (0/1) variables from questions on a survey where respondents could select one more options (e.g. bn_option1, bn_option2, ...) . Now I'd like to create bar charts for the % of '1's for each option (binary variable) of the corresponding question. One bar chart per question with as many bars as there were originally options.
Please show us a portion of this data, provided as working SAS data step code (Examples and Instructions)
Yes, Paige, I am.
That would be better to demonstrate your question by posing some data and the picture you want to see.
data have;
call streaminit(123);
array x{*} opt1-opt6;
do id=1 to 100;
do i=1 to dim(x);
x{i}=rand('bern',i/10);
end;
output;
end;
drop i;
run;
proc transpose data=have out=want;
by id;
var opt:;
run;
proc sgplot data=want pctlevel=group;
vbar _name_/group=col1 stat=percent ;
run;
Thank you. Here's sample data and a desired bar chart (without axis labeling).
| Id | Option1 | Option2 | Option3 | Option4 |
| 1 | 0 | 0 | 0 | 1 |
| 2 | 0 | 0 | 1 | 0 |
| 3 | 0 | 1 | 0 | 1 |
| 4 | 1 | 0 | 1 | 1 |
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: