Data visualization with SAS programming

Axis statement as a macro variable in Proc Gchart

Accepted Solution Solved
Reply
Super Contributor
Posts: 291
Accepted Solution

Axis statement as a macro variable in Proc Gchart

Wasn't sure whether to post this here or under the Macro section - but it's here!

This code works as expected:

axis1 label=none value=(h=1.5;;

proc gchart data=barsall;

vbar period/sumvar=pct

maxis=axis1

;

run;

When I attempt to change axis1 into a macro variable (for automation), I get an error whose cause I don't understand.  Code and log below.  Please help me to eliminate the error.  Thanks, Bill

%let axis1=label=none value=(h=1.5);

proc gchart data=barsall;

vbar period/sumvar=pct

maxis=&axis1

;

run;

Log follows

30151 %let axis1=label=none value=(h=1.5);

 

30152 proc gchart data=barsall;

NOTE: The previous statement has been deleted.

30153 vbar period/sumvar=pct

30154 maxis=&axis1

30155 ;

NOTE: Line generated by the macro variable "AXIS1".

30155 label=none value=(h=1.5)

-

22

76

ERROR 22-322: Syntax error, expecting one of the following: ;, ANNOTATE, ASCENDING, AUTOREF, CAUTOREF, CAXIS, CERROR, CFRAME, CFREQ, CLIPREF, CLM, COUTLINE, CPERCENT, CR, CREF, CTEXT, DESCENDING, DESCRIPTION, DISCRETE, ERRORBAR, FRAME, FREQ,

FRONTREF, G100, GAXIS, GROUP, GSPACE, HMINOR, HREF, HTML, HTML_LEGEND, IFRAME, IMAGESTYLE, INSIDE, LAUTOREF, LEGEND, LEVELS, LR, LREF, MAXIS, MEAN, MIDPOINTS, MINOR, MISSING, NAME, NOAXIS, NOBASEREF, NOFRAME, NOHEADING,

NOLEGEND, NOSPACE, NOZERO, OUTSIDE, PATTERNID, PERCENT, RANGE, RAXIS, REF, SPACE, SUBGROUP, SUM, SUMVAR, TYPE, VMINOR, VREF, WIDTH, WOUTLINE.

ERROR 76-322: Syntax error, statement will be ignored.

30156 run;


Accepted Solutions
Solution
‎06-29-2011 11:40 AM
SAS Employee
Posts: 967

Axis statement as a macro variable in Proc Gchart

There are probably several ways, but one way to do it is like this:

%let axis1txt=label=none value=(h=1.5);

axis1 &axis1txt;

proc gchart data=sashelp.class;
vbar height / discrete
type=sum sumvar=age maxis=axis1;
run;

View solution in original post


All Replies
Solution
‎06-29-2011 11:40 AM
SAS Employee
Posts: 967

Axis statement as a macro variable in Proc Gchart

There are probably several ways, but one way to do it is like this:

%let axis1txt=label=none value=(h=1.5);

axis1 &axis1txt;

proc gchart data=sashelp.class;
vbar height / discrete
type=sum sumvar=age maxis=axis1;
run;

Super Contributor
Posts: 291

Axis statement as a macro variable in Proc Gchart

Thanks Rob;

Is the problem then that we cannot use a macro variable directly with maxis= as in maxis=&axis1?

Bill

SAS Employee
Posts: 967

Axis statement as a macro variable in Proc Gchart

Here's the doc:

http://support.sas.com/documentation/cdl/en/graphref/63022/HTML/default/viewer.htm#gchart-bar.htm

"MAXIS=AXIS<1...99> assigns the specified AXIS definition to the midpoint axis."

maxis must point to a numbered axis<1..99> (not the values that would be defined in that axis statement)...

Valued Guide
Posts: 763

Re: Axis statement as a macro variable in Proc Gchart

I think that one way to see why this will not work is to show what you are trying  to do with that macro variable.  Your PROC looks like this after the SAS macro processor substitutes the macro text ...

proc gchart data=barsall;

vbar period/sumvar=pct

maxis=label=none value=(h=1.5);

run;

Once the text is subsituted, the compiler looks at your SAS job and finds the errors.  If you look at that PROC, I do not think that you would write anything that looks like that.  As Robert Allison pointed out, all you can have after MAXIS= is the name of an axis definition, for example MAXIS=AXIS1 (you cannot have a set of instructions and that's what you are trying to do).

Super Contributor
Posts: 291

Re: Axis statement as a macro variable in Proc Gchart

Mike - you are most correct.  It's so obvious that I should have seen it.  Your response actually made me realize that axis statements (and various others) behave like macro variables in a substitutionary sense.

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 290 views
  • 6 likes
  • 3 in conversation