Data visualization with SAS programming

create a bar chart from individual values in a numeric variable

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 124
Accepted Solution

create a bar chart from individual values in a numeric variable

Hi ,

I am new to ODS/graph and I want to create a bar chart on the individual values in a numeric variable. The values are rounded to the nearest 2nd decimal point and they pretty close in value to each other. There are 100 such values. I tried using the discrete option on proc gchart after vbar statement but I get a chart that is very crowded.  I want to know how to increase the chart area. Also, I am not sure if it worked since it was so crowded. Please advice . Unfortunately, I was not able to copy paste the data, graph or attach a file.


Accepted Solutions
Solution
‎03-18-2015 03:12 PM
SAS Super FREQ
Posts: 925

Re: create a bar chart from individual values in a numeric variable

I haven't seen your code, but consider using PROC SGPLOT instead (SAS 9.2 or greater). You will be able to use FITPOLICY=THIN to drop the crowded values. For example,

proc sgplot data=sashelp.heart;

xaxis fitpolicy=thin;

vbar AgeAtStart / response=weight stat=mean;

run;

Hope this helps!

View solution in original post


All Replies
Super User
Posts: 19,059

Re: create a bar chart from individual values in a numeric variable

Use a browser other than IE to copy/paste code. You can attach a file with graphics as well.

Solution
‎03-18-2015 03:12 PM
SAS Super FREQ
Posts: 925

Re: create a bar chart from individual values in a numeric variable

I haven't seen your code, but consider using PROC SGPLOT instead (SAS 9.2 or greater). You will be able to use FITPOLICY=THIN to drop the crowded values. For example,

proc sgplot data=sashelp.heart;

xaxis fitpolicy=thin;

vbar AgeAtStart / response=weight stat=mean;

run;

Hope this helps!

Frequent Contributor
Posts: 124

Re: create a bar chart from individual values in a numeric variable

Thanks DanH. Reeza I took your advice. I am going to try your sugesstion DanH and  the code I used was

proc gchart data=final;

  vbar var1/discrete;

run;

Here is the data that I am working on and that's the graph I need. Would proc gchart work for this ? What can I do to manipulate the chart area /

         var1
1.65
4.83
6.14
6.56
8.35
9.22
9.57
10.23
10.67
11.98
45.23
67.54
34.53

Frequent Contributor
Posts: 124

Re: create a bar chart from individual values in a numeric variable

Hi Dan, I tried your code , but I am not happy with the results. Do you have any suggestions for gchart ?

Super User
Posts: 19,059

Re: create a bar chart from individual values in a numeric variable

What version of SAS are you on?

Super User
Posts: 19,059

Re: create a bar chart from individual values in a numeric variable

You also need to be more explicit than "I'm not happy with that chart".

data have;

input var1;

cards;

1.65

4.83

6.14

6.56

8.35

9.22

9.57

10.23

10.67

11.98

45.23

67.54

34.53

;

run;

data have;

set have;

category=_n_;

run;

proc sgplot data=have;

vbarparm category=category response=var1/barwidth=0.5;

run;quit;

Frequent Contributor
Posts: 124

Re: create a bar chart from individual values in a numeric variable

Actually DanH and Reeza I take back my words. I missed adding an 'ID' to the dataset and tried sgplot again and it worked (the same way as Reeza created the category variable). I realized something was wrong soon after. But, that is not what is needed.

I need the individual value of var1 on the x-axis and its corresponding frequency on the y-axis. I tried that with gchart and it worked ,but had done it with values rounded to the nearest whole number. I need to repeat it with the values rounded to the 2nd decimal point.

Thanks to both of you for your input.

Super User
Posts: 11,114

Re: create a bar chart from individual values in a numeric variable

Have you tried applying a format like f5.2 to the Y axis variable?

Frequent Contributor
Posts: 124

Re: create a bar chart from individual values in a numeric variable

@ballardw..No I haven't, but will now . Thanks !

🔒 This topic is solved and locked.

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

Discussion stats
  • 9 replies
  • 613 views
  • 7 likes
  • 4 in conversation