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;
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;
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
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;
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.
Got it working now. Thanks for the help Dr. Allison!
Milton
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: