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

Hi,

I know it's stupid question but want to check its possible? Can we create a box plot in proc template without using the 'Boxplot' statement. The reason for this  alot of customization involved in my requirement, where box plot statement is restricting me to change because of no options available. Is it possible to create the Exact box plot using the 'Bar' and Scatterplot Statements? ( I feel like dumb while writing the requirement, unfortunately I don't have the choice)

 

Thank you for your opinions.

data dummy_data;
    call streaminit(123);
    
    do id = 1 to 10;
        group = 'A';
        value = rand('Uniform') * 30 + 20;
        output;
        
        group = 'B';
        value = rand('Uniform') * 30 + 30;
        output;
    end;
run;

proc print data=dummy_data;
run;
data dummy_data;
    call streaminit(123); /* Set seed for reproducibility */
    
    do id = 1 to 10;
        group = 'A';
        value = rand('Normal', 50, 10); /* Mean=50, SD=10 */
        output;
        
        group = 'B';
        value = rand('Normal', 65, 12); /* Mean=65, SD=12 */
        output;
    end;
run;
proc template;
    define statgraph myboxplot;
        begingraph;
            entrytitle "Comparison of Values by Group";
            layout overlay / 
                xaxisopts=(label="Group" discreteopts=(tickvaluefitpolicy=rotatethin))
                yaxisopts=(label="Measurement Value");
                
                boxplot x=group y=value / 
                    group=group
                    boxwidth=0.5
                    capshape=line
                    meanattrs=(symbol=circlefilled color=black size=8)
                    medianattrs=(color=red)
                    whiskerattrs=(pattern=solid)
                    outlierattrs=(color=blue symbol=circlefilled);
                
                referenceline y=55 / lineattrs=(color=gray pattern=dash);
                
                discretelegend "boxplot" / title="Group";
            endlayout;
        endgraph;
    end;
run;

proc sgrender data=dummy_data template=myboxplot;
run;
1 ACCEPTED SOLUTION
4 REPLIES 4
DanH_sas
SAS Super FREQ

We have a BOXPLOTPARM statement, which will give you maximum control of the DATA passed into the box plot rendering. If you are wanting to have maximum control GRAPHICALLY to build box plots, consider using the following statements (specified in this order in the Layout Overlay):

  1. HIGHLOWPLOT -- use this to draw the whiskers
  2. HIGHLOWPLOT / type=bar -- use this draw the actual box on top of the whiskers.
  3. SCATTERPLOT -- use this to draw the mean value

I'm not sure of your exact requirements, but hopefully this will get you started.

StudentSASLearn
Obsidian | Level 7

Thank you @DanH_sas . Can you please direct me to any references? if you can

StudentSASLearn
Obsidian | Level 7

Perfect. Thank you @Ksharp 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 488 views
  • 2 likes
  • 3 in conversation