How to use the ODS Graphics statement? SG Procedure.

Suppose, before the PROC SGPLOT step, we’ve added the ODS Graphics statement. After the forward slash, we have specified the width of 10 inches, and a height of 4 inches. These are global options that will impact all of SG Procedures going forward until you reset. Well, that’s what we did at the end of this procedure. We did an ODS Graphics slash reset. In addition to adding the ODS Graphics statement, we’ve also added two title statements and a footnote statement.

You now see a wider graph. Notice the titles? 1986 baseball season, total runs and home runs per team. In addition, there is a footnote that is right-justified You’ll notice, what are we doing to get our graph, is we just add a little syntax, a few pieces at a time. We started real simple with a statement, and we keep adding more statements, keep adding more options. There’s even more for us to do. For example, we might want to change attributes for our axis. Maybe change the labels or the values of the scale. Look at the y-axis.

Now, our scale is going from 0 to 1,500, incrementing by 250. Within the PROC SGPLOT step, I have added an x-axis statement, and a y-axis statement. For each axis statement, we have changed the label for the axis. In addition, for the y-axis, we are specifying that the value should start at 0, go to 1,600, and increment by 200. In addition, we are specifying that we want minor tick marks, one minor tick mark between every major tick mark. Notice the difference. We see different labels, and for the scale of the y-axis, it starts at 0, goes to 1,600, incrementing by 200. Next, let’s take this legend and change the location.

A key legends’ statement has been added. The legend will now appear inside the axis area and will be positioned in the top right. You can definitely see the location of the legend has changed. This program has been a good example. We started simple. We had a PROC statement and a run statement. Not only that, but we started off by adding a VBAR statement. That statement was real simple, but we added options. Then we added more statements, other plot statements, axis statements, key legend statements In addition, we used global statements, such as title, footnote, and ODS Graphics. It didn’t take much to get a graph, but definitely more syntax was needed to get the graph looking the way we wanted.

This is just one example of using PROC SGPLOT. Next, I want to show you additional PROC SGPLOT steps. Within this program, what I want to show you is different plot statements, showing you the different types of plots that you can create. Starting off, I have two PROC SGPLOT statements that are referencing the data set, SAS Help, period, baseball. Both steps include a where statement, where we are subsetting, where the position is in first base, second base, third base, or short stop. In the first step, instead of a VBAR statement, we are using HBAR, ha horizontal bar chart. For the horizontal bar chart, we will get a bar for each position.

In addition, we have specified options. We will group the bars by the page. Those bars will be clustered next to each other, and the length of the bar will represent the mean salary. In the second PROC SGPLOT step, we have a VBOX for salary. We want a vertical box plot representing salary. In addition, we want a different box per each category of position. Running these two steps will produce two graphs. In the first graph, we see the horizontal bar chart for each position. The red bar represents the National League, and the blue bar represents the American League. The length of each bar represents the average salary per position.

If we scroll down, we can see the box plot. With the box, plot what we see as a box. That represents from the 25th percentile to the 75th percentile. Within the box, we see a diamond and a line, which represent our mean and the median. In addition, we have whiskers to our box, and beyond the whiskers, we have outliers. What we can tell from this box plot is that the first baseman has a wider range of salary. Looking at a couple more steps. This time, using the SAS Help Table of cars.

In the first PROC SGPLOT, we are using as help cars the histogram statement and two density statements. We want a histogram of the weight of the cars, and we want each bin to be labeled. On top of that histogram, we want tensity curves. The first density curve is going to be a normal density curve, and the second is going to be a kernel. Verses in the second PROC SGPLOT for SAS help cars, we are using the Vline statement. We want a line plot. On the x-axis, we are using the type variable. On the y-axis, we want to see the mean of NPG city, and also the NPG highway. The y-axis is going to be our response axis. It’s on the response axis that we will be able to see the miles per gallon for city and highway, and it’s the average that we are looking at.

Here, we see the histogram as helping cars. It’s a histogram for the weight variable. Then on the histogram, we’ve got the normal density curve and the kernel density curve. Versus the PROC SGPLOT that created the two line plots, this was using the VLINE statements. The blue line represents the miles per gallon for the city, and the red line represents the miles per gallon of the highway. Definitely, the type of hybrid has higher numbers. Next, I want to show you three examples using a help class as the data set. In the first example, we’re going to do a band plot. For the band plot, our x-axis is height, and we want to create a shaded area from a lower value of 70 to an upper value of 120. Then, on top of the band plot, we are going to put the scatterplot, where we show on the x-axis height and the y-axis weight.

Instead of doing something like a scatter, you can do a bubble where you have an x and y, but instead of getting the same sized markers, what we have is a third argument called size. The size of the marker is going to be dependent upon the value of H. The higher the value of the H, the bigger the bubble. Another statement that follows along with the syntax of an x equals y equals, is a REG statement. This is for regression. We want to do a regression, by default, we’re going to do linear regression between height, and weight. In addition, we want confidence limits of the mean predicted values in the individual predicted values. Here, the first graph we see is the band. It’s a shaded area from 70 to 120. On top of that, we put the scatter. The band can be useful because that might be our target range for the weight. Second, I see the bubble. Each marker represents a given height and weight for a student.

The difference is the size of the bubbles are different, because the bigger the bubble, the higher the H. And the last one for sashelp.class shows a regression. A regression between height and weight. The shaded blue area represents the 95% confidence limits for the CLM, and the dashed lines are for the confidence limits of the individual predicted values. Next, I want to show you three more examples. And the first one, we’re using the data set, SAS Help, period heart. In this one, we’re doing a heat map. Heat map syntax is very similar to something like the regression or the scatter, where you do an x equals and a y equals.

Leave a Comment