BookmarkSubscribeRSS Feed
emcee825
Calcite | Level 5

Hello,

I'm trying to use the row totals within groups for the percentages in proc gchart. I did find this bit of code that works spectacularly:

proc freq data=&dsn;

  table q4*q606 /out=gd outpct noprint;

run;

proc gchart data=gd;

  vbar q4 / patternID=group group=q606

  freq=pct_row

  discrete noframe

  outside=freq inside=count

  width=&width gspace=&gspace

  raxis=axis1 maxis=axis2 gaxis=axis3

  legend;

  where q4 ne . and q606 ne .;

run; quit;

However, given that I have a lot of variables to go through like this, I wrote the following macro and though I understand why I'm getting the error that _all_ doesn't exist in the gd dataset, I'm not sure how to go about resolving that.

%macro graphsnum(dsn,dsn3,var,covar);

  proc freq data=&dsn;

  table &var*&covar/ out=&dsn3 outpct noprint;

  run;

  proc gchart data=&dsn3;

  vbar &var / patternID=group group=&covar

  freq=pct_row  outside=FREQ

  discrete noframe width=&width gspace=&gspace

  raxis=axis1 maxis=axis2 gaxis=axis3

  legend;

  where &var ne . and &covar ne . and &covar ne 3;

  run; quit;

%mend graphsnum;

%graphsnum(&dsn,&dsn3,_all_,gender);

Any sort of insight would be appreciated!

1 REPLY 1
emcee825
Calcite | Level 5

I thought I had done my due diligence prior to posting this but apparently, I hadn't been thorough enough.

I discovered that the option "g100" exists within gchart, but only if a group is specified (which makes perfect sense). My code now looks like the following & I can write a simpler macro for it now that I cut out proc freq as the middleman:

proc gchart data=a.yc_final_2;

  vbar q4 / discrete noframe

  type=PCT inside=FREQ outside=PCT

  width=&width gspace=&gspace

  raxis=axis1 maxis=axis2 gaxis=axis3

  patternID=group group=gender g100

  legend;

run;

quit;

(As a side note, I used a macro that tailors the bar widths and spaces in between them.)

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1104 views
  • 0 likes
  • 1 in conversation