BookmarkSubscribeRSS Feed
NeilH
Fluorite | Level 6

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.

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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)

--
Paige Miller
NeilH
Fluorite | Level 6

Yes, Paige, I am.

Ksharp
Super User

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;

Ksharp_0-1714445711381.png

 

NeilH
Fluorite | Level 6

Thank you. Here's sample data and a desired bar chart (without axis labeling).

 

IdOption1Option2Option3Option4
10001
20010
30101
41011

 

NeilH_0-1714485005391.png

 

sas-innovate-2024.png

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.

 

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.

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
  • 4 replies
  • 146 views
  • 0 likes
  • 3 in conversation