Data visualization with SAS programming

Pie Graph Explode

Accepted Solution Solved
Reply
Super Contributor
Posts: 326
Accepted Solution

Pie Graph Explode

Hi,

Does the explode option on a pie statement allow macro variables as its value? When the i place a hard-coded on the explode option it gives the correct display of the graph. However when i get the value on a

Anything wrong with the code below? Your help is much appreciated. Thanks!

Milton

proc sql;

          select strip(column) into: mvar

          from lib.source

          ;

quit;

proc gchart

          data=graph_src

          pie taxpayer /

                    sumvar=percentage

                    slice=arrow

                    value=inside

                    explode="&MVAR"

          ;

run;

quit;


Accepted Solutions
Solution
‎09-08-2011 08:37 AM
SAS Employee
Posts: 977

Pie Graph Explode

When you're creating the mvar macro variable, the strip() function isn't doing what you think it is, and therefore the variable is padded with blanks, and then it's not matching when you try to use it later.

Rather than using the strip() function, you'll want to use  ...   separated by ' '

Here's an example, trying the strip() which doesn't work, and then using separated by ' ' which does work:

-------

proc sql;
create table foo as select unique make, count(*) as count
from sashelp.cars group by make;
select strip(make) into :mvar from foo having count=max(count);
quit;


proc gchart data=sashelp.cars;
pie make / type=freq
   slice=arrow
   value=inside
   explode="&MVAR"
   ;
run;
quit;

----------

proc sql;
create table foo as select unique make, count(*) as count
from sashelp.cars group by make;
select make into :mvar separated by ' ' from foo having count=max(count);
quit;


proc gchart data=sashelp.cars;
pie make / type=freq
   slice=arrow
   value=inside
   explode="&MVAR"
   ;
run;
quit;

-------

Based on SASWare Ballot feedback, we've added a 'trimmed' option to to make this a little more intuitive in SAS 9.3  :-)

proc sql;
create table foo as select unique make, count(*) as count
from sashelp.cars group by make;
select make into :mvar trimmed from foo having count=max(count);
quit;


proc gchart data=sashelp.cars;
pie make / type=freq
   slice=arrow
   value=inside
   explode="&MVAR"
   ;
run;
quit;

View solution in original post


All Replies
SAS Super FREQ
Posts: 8,814

Pie Graph Explode

Hi,

Are you absolutely sure that your SQL step is creating &mvar correctly??  Do you see the expected value in the log if you have

%PUT mvar is: &mvar;

...after the QUIT statement for PROC SQL??

Cynthia

Solution
‎09-08-2011 08:37 AM
SAS Employee
Posts: 977

Pie Graph Explode

When you're creating the mvar macro variable, the strip() function isn't doing what you think it is, and therefore the variable is padded with blanks, and then it's not matching when you try to use it later.

Rather than using the strip() function, you'll want to use  ...   separated by ' '

Here's an example, trying the strip() which doesn't work, and then using separated by ' ' which does work:

-------

proc sql;
create table foo as select unique make, count(*) as count
from sashelp.cars group by make;
select strip(make) into :mvar from foo having count=max(count);
quit;


proc gchart data=sashelp.cars;
pie make / type=freq
   slice=arrow
   value=inside
   explode="&MVAR"
   ;
run;
quit;

----------

proc sql;
create table foo as select unique make, count(*) as count
from sashelp.cars group by make;
select make into :mvar separated by ' ' from foo having count=max(count);
quit;


proc gchart data=sashelp.cars;
pie make / type=freq
   slice=arrow
   value=inside
   explode="&MVAR"
   ;
run;
quit;

-------

Based on SASWare Ballot feedback, we've added a 'trimmed' option to to make this a little more intuitive in SAS 9.3  :-)

proc sql;
create table foo as select unique make, count(*) as count
from sashelp.cars group by make;
select make into :mvar trimmed from foo having count=max(count);
quit;


proc gchart data=sashelp.cars;
pie make / type=freq
   slice=arrow
   value=inside
   explode="&MVAR"
   ;
run;
quit;

Respected Advisor
Posts: 3,782

Pie Graph Explode

The new TRIMMED option is a welcome enhancement.  It might be worth mentioning there are other ways to handle the quoted blanks produce by SQL INTO.

You could simply reassign the macro variable

%let mvar=&mvar;

or use %unquote when referencing the macro variable

explode="%unquote(&mvar)

I suppose unquote would be handy if processing an "array" of macro variables.

Super Contributor
Posts: 326

Pie Graph Explode

Got it working now. Thanks for the help Dr. Allison!

Milton

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 268 views
  • 7 likes
  • 4 in conversation