BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
shasank
Quartz | Level 8

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.

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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;
PG

View solution in original post

5 REPLIES 5
ballardw
Super User

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;
shasank
Quartz | Level 8
Hi Ballardw,

Thank you for the quick reply and thank you for the solution.
I am sorry if was not clear with my question. Your solution give me an output of 0 1 2 3 on X axis. I was expecting Top medium and Low on X axis and they are further sub grouped into 0 1 2 3.
I am sorry for not being clear.
I appreciate your help.
PGStats
Opal | Level 21

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;
PG
shasank
Quartz | Level 8
Hi PGStats,

Thank you for your solution.
I appreciate your help.
I am sorry if was not clear with my question.
I was expecting Top Medium and Low in X axis which are futher each sub classified into 0 1 2 3. Just like the merging the outputs of my 3 Sgplots.
PGStats
Opal | Level 21

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;
PG

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2217 views
  • 2 likes
  • 3 in conversation