Hello SAS Community,
Thank you in advance for responding.
I was wondering if anyone could help me with plotting 3 variables namely Top Medium and Lowon X axis and Counts of those variables on Y-axis.
Each variable( Top, Medium and Low) are expected to have 0 1 2 3 observations and I want to plot all 3 variables on X axis and the frequency of 0 1 2 3 on Y axis.
Data dsn1;
input
UID $2. Top Medium Low
;
cards;
WW 1 1 1
O 1 1 1
FF 2 1 0
D 2 1 0
Y 1 2 0
BB 0 1 2
R 1 1 1
E 1 2 0
AA 1 1 1
OO 1 1 1
T 0 0 3
CC 1 0 2
;
run;
proc sgplot data = dsn1;
vbar Top/ stat = freq ;
run;
proc sgplot data = dsn1;
vbar Medium/ stat = freq ;
run;
proc sgplot data = dsn1;
vbar Low/ stat = freq ;
run;
Please comment the possibility.
Thanks.
Maybe this (third option)
data dsn2;
set dsn1;
length grp $10;
grp = "Low";
value = low;
output;
grp = "Medium";
value = medium;
output;
grp = "Top";
value = top;;
output;
run;
proc sgplot data = dsn2;
vbar value/ stat = freq group=grp groupdisplay=stack grouporder=data ;
run;
/* Or */
proc sgplot data = dsn2;
vbar value/ stat = freq group=grp groupdisplay=cluster grouporder=data ;
run;
/* Or */
proc sgpanel data=dsn2;
panelby grp / rows=1;
vbar value / stat=freq;
run;
Perhaps something like this:
Data dsn1; input UID $2. Top Medium Low ; cards; WW 1 1 1 O 1 1 1 FF 2 1 0 D 2 1 0 Y 1 2 0 BB 0 1 2 R 1 1 1 E 1 2 0 AA 1 1 1 OO 1 1 1 T 0 0 3 CC 1 0 2 ; run; data dsntrans; set dsn1; array a top medium low; do i = 1 to dim(a); Grp = vname(a[i]); value = a[i]; output; end; keep uid grp value; run; proc sgplot data = dsntrans; vbar value/ stat = freq group=grp datalabel groupdisplay=cluster; run;
Try these:
data dsn2;
set dsn1;
length grp $10;
grp = "Low";
value = low;
output;
grp = "Medium";
value = medium;
output;
grp = "Top";
value = top;;
output;
run;
proc sgplot data = dsn2;
vbar value/ stat = freq group=grp groupdisplay=stack grouporder=data ;
run;
/* Or */
proc sgplot data = dsn2;
vbar value/ stat = freq group=grp groupdisplay=cluster grouporder=data ;
run;
Maybe this (third option)
data dsn2;
set dsn1;
length grp $10;
grp = "Low";
value = low;
output;
grp = "Medium";
value = medium;
output;
grp = "Top";
value = top;;
output;
run;
proc sgplot data = dsn2;
vbar value/ stat = freq group=grp groupdisplay=stack grouporder=data ;
run;
/* Or */
proc sgplot data = dsn2;
vbar value/ stat = freq group=grp groupdisplay=cluster grouporder=data ;
run;
/* Or */
proc sgpanel data=dsn2;
panelby grp / rows=1;
vbar value / stat=freq;
run;
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!
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.