BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
milts
Pyrite | Level 9

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;

1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

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

4 REPLIES 4
Cynthia_sas
SAS Super FREQ

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

GraphGuy
Meteorite | Level 14

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;

data_null__
Jade | Level 19

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.

milts
Pyrite | Level 9

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

Milton

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 1301 views
  • 7 likes
  • 4 in conversation