turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS/GRAPH and ODS Graphics
- /
- gplot and sgplot

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-01-2017 08:09 PM - edited 07-02-2017 01:31 AM

What is the sgplot equivalent of:

```
symbol1 i=sm70;
proc gplot data=somefile;
plot resid*x / vref = 0;
```

I got a similar graph from doing:

```
proc sgplot data=somefile;
loess x=x y=resid;
refline 0;
```

But it seems like the sm70 smoothing function contributes to creating a slightly different graph from the sgplot. What am I missing from the sgplot?

Accepted Solutions

Solution

07-02-2017
02:10 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-02-2017 12:33 AM

Does it make sense to expect a SPLINE to fit a LOESS curve?

Why not use the SPLINE statement if you want a spline interpolation, which is what sm70 creates?

All Replies

Solution

07-02-2017
02:10 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-02-2017 12:33 AM

Does it make sense to expect a SPLINE to fit a LOESS curve?

Why not use the SPLINE statement if you want a spline interpolation, which is what sm70 creates?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

07-02-2017 01:30 AM

To clarify my question, I need to use sgplot instead of gplot beacuse I'm using SAS University Edition. How do I produce the same result using sgplot from the original gplot with symbol1 i=sm70?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-02-2017 02:35 AM

Can you post some data so we can replicate it to test?

Trying to read those images isn't going to cut it for testing.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

07-02-2017 02:59 AM - edited 07-02-2017 03:02 AM

```
data orig; input age plasma @@;
cards;
0 13.44 0 12.84 0 11.91 0 20.09 0 15.60
1 10.11 1 11.38 1 10.28 1 8.96 1 8.59
2 9.83 2 9.00 2 8.65 2 7.85 2 8.88
3 7.94 3 6.01 3 5.14 3 6.90 3 6.77
4 4.86 4 5.10 4 5.67 4 5.75 4 6.23
;
```

```
proc reg data=orig;
model plasma=age;
output out = notrans r = resid;
run;
/*
symbol1 i=sm70;
proc gplot data = notrans;
plot resid*age / vref = 0;
*/
proc sgplot data=notrans;
loess x=age y=resid;
refline 0;
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-02-2017 03:40 AM

Please try the

goptions interpol=sm70;

Thanks,

Jag

Jag

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Jagadishkatam

07-02-2017 12:32 PM - edited 07-02-2017 12:42 PM

Where in the code does the statement have to be inserted?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

07-02-2017 01:10 PM

You were right in trying to fit the curve using the SPLINE, I used the PBSPLINE since the SPLINE statement doesn't have the smooth option. I got the result that I wanted using the gplot sm70.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-02-2017 01:59 PM - edited 07-02-2017 02:04 PM

proc sgplot data=sashelp.enso;

pbspline y=pressure x=month;

run;

proc gplot data=sashelp.enso;

symbol1 color=blue i=sm70;

symbol2 color=red i=none v=circle;

plot pressure*month

pressure*month / overlay;

run; quit;

proc transreg data=sashelp.enso design;

model ide(pressure) = smooth(month / sm=70);

output out=b p;

run;

proc sgplot data=b;

scatter y=pressure x=month;

series y=ppressure x=month;

run;

proc gplot data=b;

symbol1 color=blue i=sm70 v=none;

symbol2 color=red i=none v=circle;

symbol3 color=green i=none v=square;

plot pressure*month pressure*month ppressure*month / overlay;

run; quit;

Personally, I would prefer the penalized b-spline, but I am biased since I wrote it. Decades ago, before ODS, users requested GPLOT smooth functions in an output data set. It was at or near the top of the sasware ballot. I knew GPLOT would never provide it, so I put it in transreg, which fits a lot of other smooth functions. You can then output the smooth function from transreg and put that smooth function into SGPLOT or GPLOT (just to reassure yourself that they are doing the same thing).

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to WarrenKuhfeld

07-02-2017 02:09 PM - edited 07-02-2017 02:10 PM

Your method of creating a data 'b' also works. But for the sake of succinctness sgplot pbspline produced the same result as gplot. Thank you for providing me with a detailed alternative.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-02-2017 02:27 PM

Are you saying you can get **precisely** the same results from pbspline in sgplot with a smoothing parameter as you get from gplot and sm70? The two methods are quite different. Or are you saying you can get similar smooths? Thanks in advance for clarifying.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to WarrenKuhfeld

07-02-2017 02:55 PM

Not precise but very close. SPLINE statement doesn't provide the smooth option, so I had no other choice other than to use the PBSPLINE.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-03-2017 05:36 AM

You can exactly reproduce the result from PROC GPLOT by using either PROC TRANSREG or PROC IML, as shown in the article "Three ways to add a smoothing spline to a scatter plot in SAS."

However, I recommend one of the statistical fits because then SAS can automatically choose the smoothing parameter based on statistical criteria. See "How to automatically select a smooth curve for a scatter plot in SAS."

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

07-03-2017 11:12 AM

But for residual plot, the transreg doesn't seem to give me the option to plot a refline.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-03-2017 11:18 AM

I'm not sure what you are saying. Transreg makes graphs, but it is not a graphing procedure per se. I just used it to add a variable to the data set that I then showed how to plot with sgplot and how to verify that it matched gplot. You can add reference lines in the usual way to sgplot.