turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS/GRAPH and ODS Graphics
- /
- How to plot 3 variables on X-axis.

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted
# How to plot 3 variables on X-axis.

[ Edited ]
Options

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

2 weeks ago - last edited 2 weeks ago

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

2 weeks ago

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

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

2 weeks ago

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

2 weeks ago

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.

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

2 weeks ago

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

2 weeks ago

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.

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

2 weeks ago

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