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
- /
- PROC GCHART bars not showing up

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

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

01-07-2016 06:33 PM

I have cigarette smoking data along with a continuous variable of interest. I compute how many cigs were smoked in the last 15, 30 and 60 minutes before the measure was taken. It turns out the the number of cigs smoked in the last 15 minutes is 0, 1 or 2, in the last 30 minuts is 0, 1, 2 or 3 and in the last 60 minutes is 0, 1, 2, 3, 4 or 5. Okay, that's all fine.

Then what I want to do is make a vertical bar chart. On the y-axis is the mean measure of interest and on the x-axis is separate bars for the number of cigs smoked. I'm using PROC GCHART. When I do it for 15 minutes it works fine and vertical bars at 0, 1 and 2 show up. When I do it for 60 minutes it works fine and vertical bars for 0, 1, 2, 3, 4 and 5 show up. Okay, still fine.

But when I do it for 30 minutes, instead of getting vertical bars at 0, 1, 2 and 3 as I should, I get vertical bars at only 0 and 3. (As an aside, although it works for 15 and 60 minutes, the x-axis ticks don't say 0, 1, 2, etc and instead say 0.0, 1.0, 2.0, etc. Maybe that's a clue in all this.)

In an AXIS statement my code has the line

order = 0 to 5 by 1;

But the bars for 1 and 2 don't show up. (Or if I change 5 to 3 then the same thing happens.)

Then I tried order = 0 to 5 by 0.1 and still the bars for 1 and 2 didn't show up.

Then I tried 0 to 5 by 0.01 and the bars for 1 and 2 DID show up. It's all squished together because I have so many points on the x-axis so I can't tell exactly where they're at, be it 1.99 or 2.01 or whatever, but the bars at (or close to) 1 and 2 are there.

Why is this? I want to use 0 to 5 by 1 (or maybe 0 to 3 by 1) and have bars at 0, 1, 2 and 3, but I can't seem to accomplish this, I guess because SAS somehow thinks the value aren't exactly 1 and 2.

I did a PROC FREQ with a format 30.28, to see 28 numbers to the right of the decimal for 0, 1, 2 and 3 and every single number to the right of the decimal is 0, e.g., it's 2.0000000000000000000000000000 rather than something else.

Any ideas? When I created these numbers I set a counter to 0 and then if a person smoked I cig I incremented the counter by 1 so I don't see how the values can be anything other than exactly 0, 1, 2 or 3.

Any info is appreciated.

Signed,

Mystified in Chapel Hill

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

01-07-2016 06:37 PM

We'd need to see the code, possible output and/or some sample data.

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

01-07-2016 06:57 PM

The values displayed on the X axis are related to the Format of the variable. Add Format Xvariablename f1.0; to the Gchart code and you should see 0, 1, 2 instead of the decimal versions.

Since your X variable is calculated it you may need to ROUND the value to an integer before graphing it.

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

01-07-2016 07:23 PM

The format thing did change 1.0, 2.0, etc to 1, 2, etc. I've never put a format in a PROC GCHART before and I never had this problem so I'm guessing that the root problem is that the numbers are not exactly 1, 2, etc as I thought they were. If they were exactly 1, 2, etc then I assume I wouldn't SAS woudln't think about decimal places. So I guess my problem is the numbers aren't exact integers.

I realize the internal storage of the computer is a whole other mystery world so even though the numbers appear as 1, 2, etc on my screen maybe they're not stored internally that way I assign X = 0 and then if an event occurs I do X = X + 1 so it seems like X should always be an integer but I guess not. When I created all this it was in a big macro that ran many times in a big loop so maybe a shortage of memory or something forced SAS to use shortcuts in memory.

I did just now create a rounded variable like

Z = round (Y)

where Y was the original variable and then I ran PROC GCHART on Z and I still got no bars at 1 and 2.

Here is the code in case that helps. I'm about to leave for home but I am going to e-mail this to myself and then work on it at home later tonight.

%MACRO PLOT (el, min);

proc sort data=plot_&EL; by z ; run;

proc means data=plot_&EL n mean stderr; by z ; var eCO; run;

axis1 label = ('Number of Cigs ' "&EL" ' in Previous ' "&MIN" ' Minutes')

order = 0 to 5 by 1;

axis2 label = ('eCO')

order = 0 to 40 by 10;

proc gchart data=plot_&EL;

vbar z /

type = mean

sumvar = eCO

errorbar = both

maxis = axis1

raxis = axis2

;

run;

%MEND PLOT;

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

01-08-2016 11:07 AM

Can you provide an example data set with the variables involved in the plot that shows this issue?

Minor style point: You are making this line more complicated than needed:

axis1 label = ('Number of Cigs ' "&EL" ' in Previous ' "&MIN" ' Minutes')

try

axis1 label = ("Number of Cigs &EL in Previous &MIN Minutes")

Breaking up the pieces of a label is really only needed if you are applying different text characteristics for different bits of the title.