BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
xxformat_com
Barite | Level 11

Hi,

The two barchart statements give the same result.

In the first one x= and y= are used.

In the second one, category= and response= are used.

Similar possibilities occur for other graphs like piechart.

Which one should be preferred? I guess there are some historical reason for one or the other but I have no clue which one was introduced first or last.

 

proc template;
    define statgraph xxbarchart;
    begingraph;

        layout overlay;
            barchart category=age response=frequency;
        endlayout;
        
    endgraph;
    end;
run;

proc template;
    define statgraph yybarchart;
    begingraph;

        layout overlay;
            barchart x=age y=frequency;         
        endlayout;
        
    endgraph;
    end;
run;


ods exclude CrossTabFreqs;
ods output CrossTabFreqs=class_stat (keep=sex age frequency _type_ 
                                     where=(_type_='11'));

proc freq data=sashelp.class;
    table sex*age;
run;

proc sgrender data=class_stat template=xxbarchart;
run;

proc sgrender data=class_stat template=yybarchart;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

Lelia is right, the required data roles is CATEGORY. 

 

If memory serves, waaay back in SAS 9.2, the required roles were X and Y, similar to other statements like SCATTERPLOT, etc.  However, to better support the "categorizing" behavior for BARCHART,  a change was made to make CATEGORY the only required role.  In this case,  the statement will summarize the data based frequency of category.

 

For backwards compatibility, an alternate was provided where one could specify both CATEGORY (or X) and RESPONSE (or Y) on the left of the '/'.  Also, the CATEGORY role can be treated both as discrete or interval.  Default is discrete, and each value is placed at equal interval.  But if a chart is desired where the values are placed on the correct scale of a linear or date variable, then TYPE= can be specified on the axisopts option.

 

Or, in the equivalent SGPLOT procedure, XAXIS TYPE=TIME can be specified as shown in the example below:

https://blogs.sas.com/content/graphicallyspeaking/2015/08/12/bar-chart-on-interval-axis-sas-9-40m3/

 

 

View solution in original post

3 REPLIES 3
LeliaM
SAS Employee

CATEGORY and RESPONSE are the documented options, so while X and Y might work, I would stick with the supported syntax that is in the documentation.  SAS Help Center: BARCHART

Jay54
Meteorite | Level 14

Lelia is right, the required data roles is CATEGORY. 

 

If memory serves, waaay back in SAS 9.2, the required roles were X and Y, similar to other statements like SCATTERPLOT, etc.  However, to better support the "categorizing" behavior for BARCHART,  a change was made to make CATEGORY the only required role.  In this case,  the statement will summarize the data based frequency of category.

 

For backwards compatibility, an alternate was provided where one could specify both CATEGORY (or X) and RESPONSE (or Y) on the left of the '/'.  Also, the CATEGORY role can be treated both as discrete or interval.  Default is discrete, and each value is placed at equal interval.  But if a chart is desired where the values are placed on the correct scale of a linear or date variable, then TYPE= can be specified on the axisopts option.

 

Or, in the equivalent SGPLOT procedure, XAXIS TYPE=TIME can be specified as shown in the example below:

https://blogs.sas.com/content/graphicallyspeaking/2015/08/12/bar-chart-on-interval-axis-sas-9-40m3/

 

 

ballardw
Super User

Historical reasons is quite likely. SAS actually does a fair amount of work to make sure that code that worked in a previous version still "works" though some minor behaviors may change. You may get notes or warnings depending on specific code about some of these option.

 

For example some documentation directly related to your question (from my 9.4.7 online help):

CATEGORY=column | expression

specifies the column or expression for the category values.

Notes You can use X= as an alternative to CATEGORY=. If you use X=, then be aware that the TIP=, TIPFORMAT=, and TIPLABEL= options recognize X as the category role and not as CATEGORY.

 

This tells me that if I were using the Tip, Tipformat or Tiblabel options then use of X= instead of Category= may yield some difference in output.

 

You will see in procedures places where you can specify an option with "alias" names. Sometimes these reflect an earlier version of the options for a procedure that has evolved.

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 266 views
  • 5 likes
  • 4 in conversation