BookmarkSubscribeRSS Feed
ash
Fluorite | Level 6 ash
Fluorite | Level 6
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;
3 REPLIES 3
ArtC
Rhodochrosite | Level 12
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).
ash
Fluorite | Level 6 ash
Fluorite | Level 6
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
ballardw
Super User
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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1003 views
  • 0 likes
  • 3 in conversation