Data visualization with SAS programming

create a bar gragh with sgplot

Accepted Solution Solved
Reply
Contributor
Posts: 65
Accepted Solution

create a bar gragh with sgplot

I want to create a bar chart using sas code with data as below with sgplot. 

 

PROC SGPLOT DATA = applications;

VBAR sys / RESPONSE = app;

VBAR sys / RESPONSE = env;

RUN;

 

Sys     app     env

 

a           67       45

b           20       54

c           35       60

d           40       78

 

Screen Shot 2018-04-22 at 2.57.16 PM.png

 

 


Accepted Solutions
Solution
a month ago
Super User
Posts: 22,823

Re: create a bar gragh with sgplot

1. Transform your data to a long format so that you have three variables: SYS, MEASUREMENT_TYPE (APP/ENV), Value (measurement).

 

SYS, Measurement_Type, Value

 

2. Sort

 

3. Use VBAR, GROUP = Measurement_Type and GroupDisplay=Cluster. 

 

If this doesn't work for you, post your code. 

I did test it and this does generate the graph indicated. 

 


@radha009 wrote:

I want to create a bar chart using sas code with data as below with sgplot. 

 

PROC SGPLOT DATA = applications;

VBAR sys / RESPONSE = app;

VBAR sys / RESPONSE = env;

RUN;

 

Sys     app     env

 

a           67       45

b           20       54

c           35       60

d           40       78

 

Screen Shot 2018-04-22 at 2.57.16 PM.png

 

 


 

View solution in original post


All Replies
Solution
a month ago
Super User
Posts: 22,823

Re: create a bar gragh with sgplot

1. Transform your data to a long format so that you have three variables: SYS, MEASUREMENT_TYPE (APP/ENV), Value (measurement).

 

SYS, Measurement_Type, Value

 

2. Sort

 

3. Use VBAR, GROUP = Measurement_Type and GroupDisplay=Cluster. 

 

If this doesn't work for you, post your code. 

I did test it and this does generate the graph indicated. 

 


@radha009 wrote:

I want to create a bar chart using sas code with data as below with sgplot. 

 

PROC SGPLOT DATA = applications;

VBAR sys / RESPONSE = app;

VBAR sys / RESPONSE = env;

RUN;

 

Sys     app     env

 

a           67       45

b           20       54

c           35       60

d           40       78

 

Screen Shot 2018-04-22 at 2.57.16 PM.png

 

 


 

Contributor
Posts: 65

Re: create a bar gragh with sgplot

Got it. but how do i transform the data. should i create new table and insert the data.

Super User
Posts: 22,823

Re: create a bar gragh with sgplot


@radha009 wrote:

Got it. but how do i transform the data. should i create new table and insert the data.


PROC TRANSPOSE or data step using an array. Tutorials below:

How to reshape data wide to long using proc transpose | SAS ...

Reshaping data wide to long using a data step | SAS ... - Stats at UCLA

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 176 views
  • 0 likes
  • 2 in conversation