Data visualization with SAS programming

gbarline with stacked bars and a percentage for the line

Reply
New Contributor ash
New Contributor
Posts: 4

gbarline with stacked bars and a percentage for the line

I am trying to insert a calculation into the plot statement in gbarline. I have code that successfully produces my stacked bars, but I cannot get the line to be a percentage. The datafile contains one record per observation, which seems to be necessary for the bars to stack correctly. Is it possible for the line to be a calculation?

I've tried putting the calculation into the plot stmt: plot / type=percent (flupos/pcr_count)

I've also tried putting the necessary denominator in the where statement as below.


proc gbarline data=six;
bar graphcode/ sumvar= ili
subgroup = subtype
clipref
width=5
FRAME MIDPOINTS=6 TO 58 BY 1
type=sum
coutline=black
raxis=axis1
maxis=axis2
legend=legend1;

plot flupos / type=percent
axis=axis3
legend=legend2;

where ili=1 and pcr_count=1;

format subtype subtype. graphcode graphcode.;

run;quit;
Valued Guide
Posts: 632

Re: gbarline with stacked bars and a percentage for the line

Just to be sure.
1) FLUPOS is a 0/1 var?
2) since you are doing a WHERE on ILI you would like the percent to be number of flu cases out of count within GRAPHCODE (across the SUBTYPE)?
3) check the specification of the PLOT statement (what version of SAS are you using).
New Contributor ash
New Contributor
Posts: 4

Re: gbarline with stacked bars and a percentage for the line

Hi!
FLUPOS is a 0/1 variable.
The "where ili=1 and pcr_count=1" statement should allow the denominator to be the number of records in the dataset. This would then plot the % flu positive, with stacked bars showing the tally of the flu positives by subgroup (the types of flu).

In the code below, my bar statement says "bar graphcode/sumvar=ili", which gives me a stack that inclues flu negatives as a part of the bar. However, I want the plot line to be limited only to the flu positives out of the # ili (oy, I hope that made sense).

I'm using SAS 9.2
Super User
Posts: 11,101

Re: gbarline with stacked bars and a percentage for the line

If FLUPOS is coded as 0/1 then MEAN instead of PERCENT will give you a percent of 1 coded responses, use an appropriate format for display.
Ask a Question
Discussion stats
  • 3 replies
  • 178 views
  • 0 likes
  • 3 in conversation