Data visualization with SAS programming

How to plot 3 variables on X-axis.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

How to plot 3 variables on X-axis.

[ Edited ]

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.

 

 

 

 

 


Accepted Solutions
Solution
2 weeks ago
Respected Advisor
Posts: 4,811

Re: How to plot 3 variables on X-axis.

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


All Replies
Super User
Posts: 11,114

Re: How to plot 3 variables on X-axis.

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;
Occasional Contributor
Posts: 12

Re: How to plot 3 variables on X-axis.

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.
Respected Advisor
Posts: 4,811

Re: How to plot 3 variables on X-axis.

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
Occasional Contributor
Posts: 12

Re: How to plot 3 variables on X-axis.

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.
Solution
2 weeks ago
Respected Advisor
Posts: 4,811

Re: How to plot 3 variables on X-axis.

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
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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