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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 1 reply
  • 906 views
  • 0 likes
  • 1 in conversation