Data visualization with SAS programming

PROC GCHART -- using row totals within groups

Reply
Occasional Contributor
Posts: 11

PROC GCHART -- using row totals within groups

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!

Occasional Contributor
Posts: 11

Re: PROC GCHART -- using row totals within groups

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.)

Post a Question
Discussion Stats
  • 1 reply
  • 370 views
  • 0 likes
  • 1 in conversation